home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / spectr20.zip / SPECTRUM.DOC < prev    next >
INI File  |  1992-04-29  |  155KB  |  3,200 lines

  1. [WS 1.5 in]
  2.  
  3.                          SPECTRAL  ANALYSIS  ON  A  PC
  4.  
  5. [WS 3.5 in]
  6.  
  7.                                  David E. Hess
  8.                                 Fluid Flow Group
  9.                          Process Measurements Division
  10.                    Chemical Science and Technology Laboratory
  11.                  National Institute of Standards and Technology
  12.                             Email: HESS@ENH.NIST.GOV
  13.                              Phone: (301) 975-5937
  14.  
  15. [WS 0.5 in]
  16.  
  17.                                   [December 1991]
  18.  
  19.  
  20.                                     Abstract
  21.  
  22.      These notes are intended to serve as a brief instruction manual for
  23. engineers engaged in the spectral analysis of experimentally-derived random
  24. data.  This manual is intended to accompany a software routine (Spectrum
  25. Calculation Routine, V 1.0, David E. Hess) designed to compute amplitude
  26. density, autospectral (power) density and cross-spectral density functions for
  27. discrete, stationary random time series.  This program will run on any
  28. PC-compatible desktop computer and accepts input data files obtained from
  29. experiments in which analog data has been digitized by an analog-to-digital
  30. converter.
  31.      A collection of techniques are described which are necessary for the
  32. proper software implementation of spectral analysis procedures: data
  33. transformation, mean value and linear trend removal, digital filtering, time
  34. history tapering and data overlapping.  The various spectral density functions
  35. are then defined and explained along with a means for the calculation of the
  36. error associated with a particular estimate.  Several detailed examples are
  37. included which serve to illustrate the methods described.  The manual also
  38. contains a brief description of the considerations necessary when sampling the
  39. data to be analyzed.  References to more complete sources of information are
  40. provided as required.
  41.  
  42.  
  43.                                 Notice to Users
  44.  
  45.      This program was developed for use with the ongoing Compliant Surface
  46. Program in the Fluid Flow Group; this group is a part of the Process
  47. Measurements Division at the National Institute of Standards and Technology.
  48. With the evolution of the SPECTRUM routine to its present form, the author felt
  49. that the program may perhaps be of some utility to others.  Therefore, SPECTRUM
  50. is being released as freeware.  This program, the source code and accompanying
  51. utilities may be freely copied and distributed, but may not be sold.  There is
  52. no warranty of SPECTRUM's suitability for any purpose, nor any acceptance of
  53. liability, express or implied.
  54.      Originally, the SPECTRUM routine was designed to run on any IBM-PC or
  55. compatible computer using the Intel 80x86 series of microprocessors.  However,
  56. the code was compiled using the Microsoft Fortran Optimizing Compiler, V 5.00,
  57. and this compiler allows the selection of a variety of options at compile-time
  58. which enhance the speed of operation of the program but limit its suitability
  59. for use with certain computers.  The version contained on the diskette requires
  60. a computer equipped with an 80286 or better microprocessor and an accompanying
  61. 80287 or better coprocessor.  A version of the routine which will run on
  62. computers with an 8086 or 8088 processor, or a version which does not require a
  63. numeric coprocessor can be obtained by contacting the author.  The program uses
  64. about 450K bytes of available RAM, and requires that a hard disk or RAM disk be
  65. available for storage of temporary files.  The amount of space to be reserved
  66. depends upon the size of the data file to be processed, but can easily be as
  67. much as several megabytes.
  68.      Microsoft has announced the release of V 5.1 of their Fortran compiler.
  69. To this version the capability of porting programs to the Windows environment
  70. has been added.  This is significant only in that it allows the use of the DOS
  71. extender which is a part of the Windows environment.  Fortran programs written
  72. for Windows are not limited by the DOS memory restriction of 640K, but instead
  73. can access substantially larger amounts of available RAM at run-time.  This can
  74. greatly increase the utility and speed of the SPECTRUM routine, and a version
  75. incorporating these improvements may be available at a later date.
  76.      This program has been subjected to extensive testing and appears to be
  77. free of any bugs; however, it is possible that not all situations have been
  78. anticipated.  The author encourages any modifications to or customization of
  79. the source code as required by the user, and welcomes any suggested
  80. improvements or bug-fixes.  Please direct all correspondence to the address
  81. given below.
  82.  
  83.  
  84.                        National Institute of Standards
  85.                                and Technology
  86.                        Building 230   Room 105
  87.                        Gaithersburg, MD 20899
  88.                        Attn   : David E. Hess
  89.  
  90.                        Phone  : (301) 975-5937
  91.                        Fax    : (301) 258-9201
  92.                        Email  : HESS@ENH.NIST.GOV
  93.  
  94. [PB Odd Page]
  95.  
  96.                                Table of Contents
  97.  
  98. 1 Overview and Parameters [LN String:"."]                                1
  99.  
  100. 2 Input Data Files [LN String:"."]                                       3
  101.    2.1 Naming Convention [LN String:"."]                                 3
  102.    2.2 File Structure [LN String:"."]                                    3
  103.       2.2.1 File Header [LN String:"."]                                  3
  104.       2.2.2 Remainder of Data File [LN String:"."]                       4
  105.       2.2.3 Writing and reading the Data File [LN String:"."]            5
  106.    2.3 Multiple File Processing [LN String:"."]                          6
  107.       2.3.1 Consecutively numbered files [LN String:"."]                 6
  108.       2.3.2 Arbitrarily numbered files [LN String:"."]                   7
  109.       2.3.3 Files entered on command line [LN String:"."]                7
  110.    2.4 Coefficient Data Files [LN String:"."]                            8
  111.       2.4.1 Naming Convention [LN String:"."]                            8
  112.       2.4.2 Unformatted File Structure [LN String:"."]                   8
  113.       2.4.3 Formatted Data Files [LN String:"."]                         10
  114. 3 Data Preparation [LN String:"."]                                       11
  115.    3.1 Transformation [LN String:"."]                                    11
  116.    3.2 Mean Removal [LN String:"."]                                      13
  117.    3.3 Removal of Linear Trend [LN String:"."]                           14
  118.    3.4 Filtering [LN String:"."]                                         14
  119.    3.5 Tapering [LN String:"."]                                          18
  120. 4 Spectrum Computation [LN String:"."]                                   25
  121.    4.1 Fast Fourier Transform [LN String:"."]                            25
  122.    4.2 Autospectral (Power) Density [LN String:"."]                      27
  123.    4.3 Cross-spectral Density [LN String:"."]                            29
  124.       4.3.1 Calculation Procedure [LN String:"."]                        29
  125.       4.3.2 Adjustment of Phase Angle [LN String:"."]                    30
  126.       4.3.3 Coherence Function [LN String:"."]                           35
  127.       4.3.4 Error Estimates [LN String:"."]                              35
  128.    4.4 Amplitude Spectral Density [LN String:"."]                        37
  129. 5 Output Data Files [LN String:"."]                                      41
  130.    5.1 Naming Convention [LN String:"."]                                 41
  131.    5.2 File Structure [LN String:"."]                                    41
  132.       5.2.1 Power Spectrum Output Files [LN String:"."]                  41
  133.       5.2.2 Cross Spectrum Output Files [LN String:"."]                  42
  134.       5.2.3 Amplitude Spectrum Output Files [LN String:"."]              43
  135.       5.2.4 Error Estimate Output Files [LN String:"."]                  44
  136. 6 Run-time Considerations [LN String:"."]                                45
  137.    6.1 Configuration File [LN String:"."]                                45
  138.    6.2 Temporary Files [LN String:"."]                                   46
  139. 7 Examples [LN String:"."]                                               49
  140.    7.1 Colored Noise [LN String:"."]                                     49
  141.    7.2 Sinusoidal Input [LN String:"."]                                  56
  142.    7.3 Experimental Noise Input [LN String:"."]                          61
  143.    7.4 Sampling Considerations [LN String:"."]                           64
  144. 8 Utility Routines [LN String:"."]                                       67
  145.    8.1 MAKDAT routine [LN String:"."]                                    67
  146.    8.2 MAKCOEF routine [LN String:"."]                                   69
  147. 9 References [LN String:"."]                                             73
  148.  
  149.  
  150.                  ^S▒1 Overview and Parameters
  151.  
  152.      This program is designed to compute amplitude density, autospectral
  153. (power) density and cross-spectral density functions for discrete, stationary
  154. random time series in the form
  155.  
  156.  
  157. [EQUATION "center x sub n #3#3 = #3#3 x #3 (t sub 0 + n Delta t) #4#4 #R[for]
  158. #3
  159.  
  160.  
  161.  
  162. where  [EQUATION "N", Position:In Text]  is the number of data points per
  163. record.  Typically,  [EQUATION "M", Position:In Text]  such records are stored
  164. in a data file, and each record is a contiguous segment of the stationary
  165. process.  Most often, this data is in the form of 2-byte integers after having
  166. been digitized by an analog to digital converter.  This routine reads this data
  167. file and then transforms the integer data back into voltages or optionally into
  168. some other desired quantity.  This transformation into a dimensional quantity
  169. is by means of a polynomial of up to fourth degree.  The coefficients necessary
  170. to complete the transformation are placed in coefficient data files which are
  171. read by the routine.  Alternatively, the routine can read 4-byte floating-point
  172. data which has already been transformed by some other program.  The input data
  173. may consist of one or two separate time series which are to be analyzed.
  174.  
  175.      After transformation, various cosmetic operations may be performed on the
  176. data prior to the spectrum computation.  The mean value, which is calculated
  177. during the transformation process, may be subtracted from the data; or instead,
  178. a linear trend in the data may be removed using a least squares fit technique.
  179. Recursive digital filters including lowpass, highpass, bandpass and bandstop
  180. have been incorporated and may be applied prior to the calculation of the
  181. spectra.  Finally, to reduce the leakage of power from other frequencies due to
  182. the fact that the input time series are of finite length and are then
  183. truncated, a tapering operation has been included.  A choice of four tapering
  184. functions is supplied, and the appropriate scale factors are computed
  185. automatically.  The use of tapering may introduce some additional variability
  186. in the resulting spectral estimate; to counteract this tendency, a means for
  187. overlapping the input data records is provided.  This option employs 50%
  188. overlap to reduce overall error at the expense of computation time (which is
  189. doubled); however, the use of overlapping requires that the data be contiguous
  190. in time from record to record.
  191.  
  192.      After computation of the selected spectral density function, the data are
  193. stored to an ASCII output file which may then be imported into a plotting
  194. program.  The routine is designed for multiple file processing; many input data
  195. files may be processed sequentially if certain naming conventions are
  196. followed.  The maximum number of files is currently set to IFMAX = 100 in order
  197. to allocate storage for data.  Entering data file names on the command line
  198. upon invocation of the program is also permitted and the maximum is set to
  199. JFMAX = 5.  Each record of the input data file may contain no more than NMAX =
  200. 16384 points; note that in the case of two channels of data per record, each
  201. channel may contain no more than NMAX / 2 points.  As described below, the
  202. order of the recursive digital filters is set by the number of cascaded stages
  203. desired; the maximum number of stages is currently placed at NSMAX = 20.  For
  204. convenience, the base 10 logarithms of certain data in the output are computed;
  205. to avoid taking the logarithm of zero, any number in the output data less than
  206. [EQUATION "epsilon #3 = #3 1.0 #3 x #3 10 super [-20]", Position:In Text]  is
  207. set equal to  [EQUATION "epsilon", Position:In Text] .  Any of these maximum
  208. values may be altered by making a change in the appropriate PARAMETER statement
  209. near the beginning of the code and then recompiling.
  210.  
  211.      The speed of the routine is limited by the large number of I/O operations
  212. that are required; reduce the number of points per record and/or the number of
  213. records per file for increased speed.  Alternatively, specify in the
  214. configuration file that the routine use a RAM disk for storage of temporary
  215. files.  The size of the executable file is largely governed by the setting of
  216. NMAX; since this parameter must be a power of two, the largest possible value
  217. is 16384 for a DOS-based computer which results in an executable file size of
  218. 430K bytes.  The CHKDSK command must report that at least 450K bytes of memory
  219. are present for the routine to execute for this value of NMAX.  When compiling
  220. the source code using Microsoft Fortran V 5.00, at least 603K of RAM must be
  221. available for full optimization of the code.
  222.  
  223.      When the data to be processed by the spectrum routine are samples of a
  224. continuous function of time at a single spatial location, then the calculated
  225. spectral density functions are a function of frequency.  The user should keep
  226. in mind that if the input data are samples of a continuous function of one
  227. spatial direction at an instant of time (such as intensity data for horizontal
  228. or vertical rows of pixels on a photograph from a CCD camera), then this
  229. routine can be used to determine one-dimensional estimates of wavenumber
  230. spectra.
  231.  
  232.                     ^S▒2 Input Data Files
  233.  
  234.      For any routine in which the processing of large amounts of data is
  235. required, a rather rigid structure is necessarily imposed on the manner in
  236. which the data is transferred into the program for manipulation.  The spectrum
  237. routine is certainly no exception to this rule.  Furthermore, since the
  238. spectrum routine has the ability to process data files in batches, additional
  239. rules are required, such as naming conventions, to allow this feature to be
  240. implemented.  Although the proliferation of rules can be a bit wearying, later
  241. sections discuss some situations in which the rules can be bent or discarded.
  242.  
  243. 2.1 Naming Convention
  244.  
  245.      A convention for naming the input data files was chosen to facilitate
  246. multiple file processing.  The selected method resulted from the ease with
  247. which the file names could be generated by a few lines of code.  Each file name
  248. consists of eight characters: the first character must be alphabetic (A-Z), the
  249. next three characters are digits (0-9) and the remaining four characters are a
  250. period followed by the letters DAT.  Note that the routine is not
  251. case-sensitive, lower-case as well as upper-case characters may be entered;
  252. however, all lower-case inputs are converted to upper-case internally.  The
  253. routine automatically appends the suffix [.DAT] and therefore it should never
  254. be entered upon input.  The data file must reside in the same directory as the
  255. executable file unless specified otherwise in the configuration file (discussed
  256. later).  Examples of acceptable data file names are: A001.DAT, z087.dat and
  257. M418.DAT.  The latter filename would require that IFMAX
  258. [EQUATION ">=", Position:In Text] 418.  Every rule has an exception; data file
  259. names entered on the command line when calling the routine need not be so
  260. restrictive as outlined above.  They must still consist of eight characters and
  261. the first character must still be alphabetic (A-Z); however, the next three
  262. characters can be any of the alphanumeric characters.  The blank character is
  263. used to delimit the names on the command line and is therefore not a valid
  264. character for a file name.  The remaining four characters must be a period
  265. followed by the letters DAT.  Examples of acceptable filenames for files
  266. entered on the command line are: TEST.DAT, x_in.dat and S1$$.DAT.  When
  267. actually entering the names on the command line, only the first four characters
  268. are entered and the program appends [.DAT].
  269.  
  270. 2.2 File Structure
  271.  
  272.      All input data files must be FORTRAN data files opened as sequential,
  273. unformatted files.  The minimal amount of internal formatting allows the files
  274. to be more compact which is a consideration when dealing with large quantities
  275. of data.
  276.  
  277.      2.2.1 File Header
  278.  
  279.      The first record of the data file consists of a header containing four
  280. quantities which characterize the data which follows. The first quantity is a
  281. 2-byte integer which gives the number of channels of data per record (1 or 2).
  282. The next number is the record size in bytes and may be either a 2-byte or a
  283. 4-byte integer.  The record size is twice the number of points per record if
  284. the data consists of 2-byte integer values, or the record size is four times
  285. the number of points per record if the data consists of 4-byte real data.  The
  286. third quantity is a 2-byte integer which gives the number of records of data
  287. which follow, and the last quantity is the time interval in microseconds
  288. between data points of the same channel expressed as a 2-byte integer.  Recall
  289. that the largest positive signed number that may be stored as a 2-byte integer
  290. is 32,767 and, for a 4-byte integer, the value is 2,147,483,647.
  291.  
  292.      For example, suppose the data file consists of 100 records of one channel
  293. of data saved as 2-byte integers and sampled at 10000 samples per second with
  294. 2048 data points per record.  The file header would contain the four values:
  295.  
  296.  
  297. [EQUATION "center 1 #4#4 4096 #4#4 100 #4#4 100 #4#4"]
  298.  
  299.  
  300. Now suppose that two channels of data were sampled with a time interval of
  301. 0.016383 seconds between each successive data point resulting in a time
  302. interval of 0.032766 seconds between each successive data point of the same
  303. channel.  Furthermore, 40 records of data were sampled with 8192 data points
  304. per record such that each channel of data consisted of 4096 data points.
  305. Finally, the data were transformed into desired quantities and saved as 4-byte
  306. floating-point numbers.  The header for this data file should consist of the
  307. following four numbers:
  308.  
  309.  
  310. [EQUATION "center 2 #4#4 32768 #4#4 40 #4#4 32766"]
  311.  
  312.  
  313.      2.2.2 Remainder of Data File
  314.  
  315.      Following the first record containing the file header is the actual data.
  316. When the data comes directly from an analog to digital converter (12-bit, say),
  317. then the values range from -2048 to 2047 (or 0 to 4095) and are appropriately
  318. stored as 2-byte integers.  Alternatively, if some preprocessing is typically
  319. performed on the data, the data may be stored as 4-byte floating-point
  320. numbers.  As a result of the Fast Fourier Transform (FFT) algorithm used in
  321. this routine, the number of data points per channel per record must be a power
  322. of 2.  One or two separate time series may be stored per record.  If only one
  323. channel of data is sampled then an even number of records following the file
  324. header should be stored in the data file.  This is necessary because in the
  325. case of one channel of data, two records are submitted to the FFT algorithm to
  326. be transformed simultaneously as a time-saving measure.  If an odd number of
  327. records is detected, then the program automatically appends an additional
  328. record of data containing a copy of the data values of the previous record.
  329. When two channels of data are sampled, the number of records may be even or
  330. odd.  The method of storing the data values in each record follows the standard
  331. procedure used by analog to digital converters:
  332.  
  333.  
  334. [EQUATION "center #R[one] #4 #R[channel] #^ #R[:] #4#4 x sub 0 #3 x sub 1 #3 x
  335. s
  336.  
  337.  
  338.  
  339. where the notation is as defined above.  This convention must be followed even
  340. if the data are processed and then stored as floating-point numbers.  When two
  341. channels of data are sampled and then stored to a data file, the values for
  342. each channel of data should be of the same data type: either 2-byte integers or
  343. 4-byte floating-point numbers.  If the user is unfamiliar with the task of
  344. creating unformatted FORTRAN data files, then the user may instead create these
  345. files in an ASCII file format.  A utility MAKDAT which is included on the
  346. diskette can then be used to write the file header and transform the ASCII data
  347. files into the unformatted FORTRAN data files required by the spectrum
  348. routine.  See the section on utility files.
  349.  
  350.      2.2.3 Writing and reading the Data File
  351.  
  352.      This section gives a few lines of code which are representative of the
  353. manner in which these data files are written and read.  When writing, the file
  354. is first opened, the file header is written, the data is written and then the
  355. file is closed.
  356.  
  357.  
  358.                    INTEGER*2 ICHANS, IRSIZE, NUMREC, IDELTMS
  359.                    INTEGER*2 NDATA (NMAX)
  360.  
  361.                    OPEN (2, FILE = 'A001.DAT', STATUS = 'UNKNOWN',
  362.                          ACCESS = 'SEQUENTIAL', FORM = 'UNFORMATTED')
  363.  
  364.                    WRITE (2) ICHANS, IRSIZE, NUMREC, IDELTMS
  365.  
  366.                    DO J = 1, NUMREC
  367.                       ... put data record into NDATA array ...
  368.                      WRITE (2) (NDATA (I), I = 1, N)
  369.                       ... get next record of data ...
  370.                    ENDDO
  371.  
  372.                    CLOSE (2, STATUS = 'KEEP')
  373.  
  374.      The same procedure is followed when the data file is opened and read by
  375. the spectrum routine.  The file is opened, the file header is read, the data is
  376. read and then the routine is closed.
  377.  
  378.  
  379.                    INTEGER*2 ICHANS, IRSIZE, NUMREC, IDELTMS
  380.                    INTEGER*2 NDATA (NMAX)
  381.  
  382.                    OPEN (2, FILE = 'A001.DAT', STATUS = 'OLD',
  383.                          ACCESS = 'SEQUENTIAL', FORM = 'UNFORMATTED')
  384.  
  385.                    READ (2) ICHANS, IRSIZE, NUMREC, IDELTMS
  386.  
  387.                    N = IRSIZE/2
  388.                    DELT = FLOAT (IDELTMS) / 1000000.0
  389.  
  390.                    DO J = 1, NUMREC
  391.                      READ (2) (NDATA (I), I = 1, N)
  392.                       ... process this record of data ...
  393.                    ENDDO
  394.  
  395.                    CLOSE (2, STATUS = 'KEEP')
  396.  
  397. 2.3 Multiple File Processing
  398.  
  399.      This routine is capable of sequentially processing many files in a batch.
  400. The program will handle up to IFMAX files which are consecutively numbered or
  401. which are not consecutively numbered but have an arbitrary numbering
  402. arrangement.  All data files in the batch must start with the same first
  403. letter.  The letter and number combination in the file name are used to
  404. associate each data file to a corresponding set of coefficients (if needed) in
  405. an accompanying coefficient data file; this is the reason for the rather rigid
  406. naming convention.  Alternatively, up to JFMAX files may be entered on the
  407. command line when calling the program, and these will be processed
  408. sequentially.  These files need not have the same first letter; however, these
  409. data files also cannot use coefficient data files.  This is further clarified
  410. below.  All data files must conform to the naming convention described above.
  411. The selection of options to perform various operations on the data will then be
  412. applied to all files in the batch.
  413.  
  414.      2.3.1 Consecutively numbered files
  415.  
  416.      If it is desired to process several files in a consecutive order, then
  417. this option is selected. The routine will ask for the beginning and ending file
  418. numbers and then the first letter in the file names. As an example, suppose it
  419. was desired to process files C031.DAT through C094.DAT, then the user would
  420. respond as follows:
  421.  
  422. spectrum
  423.  
  424. Process files (C)onsecutively or in an (A)rbitrary order : c
  425.  
  426. Enter starting & ending data file # : 31 94  (or 31,94)
  427.  
  428. Enter first letter of data file : c
  429.  
  430.      2.3.2 Arbitrarily numbered files
  431.  
  432.      Perhaps it is not desirable to process all of the files indicated above,
  433. but only selected ones from the set.  If it were necessary to process C031.DAT,
  434. C042.DAT, C067.DAT and C085.DAT, then the user would respond as follows.
  435.  
  436. SPECTRUM
  437.  
  438. Process files (C)onsecutively or in an (A)rbitrary order : A
  439.  
  440. Enter number of files to process : 4
  441.  
  442. Enter last digits of file   1 : 31
  443. Enter last digits of file   2 : 42
  444. Enter last digits of file   3 : 67
  445. Enter last digits of file   4 : 85
  446.  
  447. Files are :
  448.            31 42 67 85        (routine echoes file numbers selected)
  449.  
  450. Enter first letter of data file : C
  451.  
  452.      2.3.3 Files entered on command line
  453.  
  454.      This option was added as a means of processing a few files without having
  455. to answer all of the prompts above and to allow a bit more freedom in the
  456. selection of file names.  Suppose it was desired to process TSTX.DAT, X_IN.DAT
  457. and WOW!.DAT, then the user would enter the following command line.
  458.  
  459. SPECTRUM TSTX X_IN WOW!
  460.  
  461. By relaxing the naming convention, it is no longer possible to easily associate
  462. a coefficient data file with the correct input data file.  Therefore, if the
  463. user desires to transform the integer data in each of the input files to
  464. voltages only, or if the input data in each file already consists of
  465. transformed floating-point numbers (as a result of some other program), then
  466. coefficient data files are not necessary and this method for quickly processing
  467. a small number of files may be used.  If the integer data in each input file
  468. must be transformed into a desired floating-point quantity using a polynomial
  469. transformation prior to the spectral calculation, then the program must be
  470. initiated using the methods described in sections 2.3.1 or 2.3.2.  Further
  471. discussion on the manner in which coefficient data files are associated with
  472. the respective input data files appears below.
  473.  
  474. 2.4 Coefficient Data Files
  475.  
  476.      These data files may be sequential unformatted or sequential formatted
  477. FORTRAN data files.  They contain the constants which are used as the
  478. coefficients of the polynomial that transforms the input data from voltages to
  479. some other desired quantity.
  480.  
  481.      2.4.1 Naming Convention
  482.  
  483.      The coefficient data file names consist of eight characters.  The first
  484. letter must be alphabetic (A-Z) and must be the same letter as the input data
  485. file (or series of input data files) with which it is associated.  The spectrum
  486. routine assigns the remaining seven characters of the name as CON.DAT (if the
  487. file is unformatted) or CON.PRN (if the file is formatted).  If the input data
  488. file D061.DAT were to be transformed from voltages into velocities, then the
  489. coefficients of the polynomial would be found in the coefficient data file
  490. named DCON.DAT (if unformatted) or DCON.PRN (if formatted), and this file must
  491. reside in the same directory as that of the executable routine and the input
  492. data file unless specified otherwise in the configuration file (discussed
  493. later).  If D061.DAT contained two channels of data, then the coefficients
  494. needed to transform the data for the second channel would be found in the
  495. coefficient data file named DCON2.DAT (if unformatted) or DCON2.PRN (if
  496. formatted).  Again, the routine requests that the user enter the first letter
  497. only and the remaining eight characters are automatically assigned by the
  498. routine.
  499.  
  500.      2.4.2 Unformatted File Structure
  501.  
  502.      These coefficient data files are accessed only if the input data are
  503. 2-byte integers and the user desires to convert the integers first into
  504. voltages and then into another quantity.  The voltage transformation factor is
  505. not included in these files; instead, it is entered into the routine at the
  506. beginning and therefore applies to all files processed.  If a series of files
  507. are to be processed, the coefficients for the transformation from voltages into
  508. the other quantity may not be the same for all files in the batch, and this
  509. situation is addressed as follows.  The conversion from a voltage into a
  510. velocity, say, for each data point is carried out using
  511.  
  512.  
  513. [EQUATION "center u sub n #3#3 = #3#3 b sub 0 #3 + #3 b sub 1 v sub n #3 + #3 b
  514.  
  515.  
  516.  
  517. where  [EQUATION "v sub n", Position:In Text]  is the nth data point expressed
  518. as a voltage,
  519. [EQUATION "b sub 0 #1 , #3 b sub 1 #1 , ... , b sub 4", Position:In Text]  are
  520. the coefficients of the velocity transformation and
  521. [EQUATION "u sub n", Position:In Text]  is the nth data point which has been
  522. converted to a velocity.  The five coefficients of the transformation remain
  523. the same for each data point in each record of the file, but are permitted to
  524. vary from file to file.  These constants are stored in a two-dimensional array
  525. of 4-byte floating-point numbers.  The first index of the array is the number
  526. of the file to which the coefficients are to apply (1 to IFMAX), and the second
  527. index is the number of the coefficient (1=
  528. [EQUATION "b sub 0", Position:In Text] to 5=
  529. [EQUATION "b sub 4", Position:In Text] ).  The first record of the unformatted
  530. coefficient data file is a file header containing two 2-byte integer
  531. quantities: the first is the number of sets of coefficients to read, and the
  532. second is the starting file number to which these coefficients should be
  533. associated.  The remainder of the data file consists of one large record
  534. containing all of the coefficients.  If the user wishes to first create these
  535. coefficient data files in an ASCII file format (without the header), the
  536. utility MAKCOEF has been included on the diskette which will convert these
  537. ASCII files into the unformatted FORTRAN files needed by the spectrum routine.
  538. See the section on utility routines.  An example of the code used to write and
  539. read a sequential unformatted coefficient data file follows.
  540.  
  541.  
  542.          INTEGER*2 NUMSETS, NUMCON, NSTART
  543.          REAL*4 CONST (IFMAX, 5)
  544.  
  545.          NUMCON = 5
  546.  
  547.          OPEN (2, FILE = 'DCON.DAT', STATUS = 'UNKNOWN',
  548.                ACCESS = 'SEQUENTIAL', FORM = 'UNFORMATTED')
  549.  
  550.          WRITE (2) NUMSETS, NSTART
  551.          WRITE (2) ((CONST (I,J), J = 1, NUMCON), I = 1, NUMSETS)
  552.  
  553.          CLOSE (2, STATUS = 'KEEP')
  554.  
  555.  
  556. The spectrum routine then reads the coefficient data file using code of the
  557. following form.
  558.  
  559.  
  560.          INTEGER*2 NUMSETS, NUMCON, NSTART
  561.          REAL*4 CONST (IFMAX, 5)
  562.  
  563.          OPEN (2, FILE = 'DCON.DAT', STATUS = 'OLD',
  564.                ACCESS = 'SEQUENTIAL', FORM = 'UNFORMATTED')
  565.  
  566.          READ (2) NUMSETS, NSTART
  567.          READ (2) ((CONST (NSTART + I - 1, J), J = 1, NUMCON), I = 1, NUMSETS)
  568.  
  569.          CLOSE (2, STATUS = 'KEEP')
  570.  
  571.  
  572. The coefficients
  573. [EQUATION "b sub 0, #1 b sub 1, #1 ... #1 , #1 b sub 4", Position:In Text]  for
  574. the data file D061.DAT are then given by CONST (61,1), CONST (61,2), ... ,
  575. CONST (61,5).
  576.  
  577.      2.4.3 Formatted Data Files
  578.  
  579.      It is not always convenient to store coefficients in sequential
  580. unformatted data files.  This option was included to allow a quick way of
  581. storing coefficients.  A sequential formatted file is exactly that created by
  582. any simple text editor.  To create a sequential formatted coefficient data file
  583. for the input data file D061.DAT, enter a text editor or word processor
  584. (capable of creating ASCII files) and give the file the name DCON.PRN.  Next,
  585. enter the five coefficients,
  586. [EQUATION "b sub 0, #1 b sub 1, #1 ... #1 , #1 b sub 4", Position:In Text], one
  587. per line and then save the file.  If you display the file to the screen, it
  588. should look something like the following.  Note that the numbers should all be
  589. floating-point numbers.
  590.  
  591.  
  592.                    3.14159265359            (
  593. [EQUATION "b sub 0", Position:In Text])
  594.                    0.0                      (
  595. [EQUATION "b sub 1", Position:In Text])
  596.                    1.012345E-03             (
  597. [EQUATION "b sub 2", Position:In Text])
  598.                    0.1                      (
  599. [EQUATION "b sub 3", Position:In Text])
  600.                    2.3E-05                  (
  601. [EQUATION "b sub 4", Position:In Text])
  602.  
  603.  
  604. An example of the code that the spectrum routine will use to read in this data
  605. file follows.
  606.  
  607.  
  608.                    REAL*4 B (5), CONST (IFMAX, 5)
  609.  
  610.                    OPEN (2, FILE = 'DCON.PRN', STATUS = 'OLD')
  611.                      READ (2, *) (B (I), I = 1, 5)
  612.                    CLOSE (2, STATUS = 'KEEP')
  613.  
  614.                    DO I = 1, IFMAX
  615.                      DO J = 1, 5
  616.                        CONST (I, J) = B (J)
  617.                      ENDDO
  618.                    ENDDO
  619.  
  620.  
  621. As is seen from the above code, the routine assigns the five constants to apply
  622. to all of the IFMAX different input data files that might be read.  If a
  623. different set of constants is required for each data file, then the files must
  624. be processed one at a time, or sequential unformatted data files as described
  625. above must be used.  If an input data file (D061.DAT, say) contains two
  626. channels of information, then a second sequential formatted data file with the
  627. name DCON2.PRN should be prepared as described above.
  628.  
  629.                     ^S^^Data Preparation
  630.  
  631.      This section deals with a sequence of cosmetic operations which may be
  632. applied to the data prior to performing spectral calculations.  The first
  633. section discusses the transformation of the input data from integer values into
  634. voltages and then optionally into some other desired dimensional quantity (for
  635. example, velocities).  If the input data consists of floating-point values,
  636. then the transformation operation is skipped.  If desired, the mean value may
  637. be removed from each record of the input data, or a linear trend resulting,
  638. perhaps, from instrumentation drift may be removed from each record.  Unwanted
  639. frequencies in the input data can be removed using the recursive digital
  640. filtering routines discussed below.  Finally, a tapering operation which may be
  641. coupled with a 50% overlap of the input data records is included to eliminate
  642. the discontinuities found at the beginning and end of these records resulting
  643. from the fact that only a finite amount of data can be sampled.  Currently, the
  644. user has a choice of four different window functions.  If the input consists of
  645. two channels of data, then the first three operations: transformation, mean or
  646. trend removal and filtering may be different for each of the two input
  647. channels.  The choice of whether or not to employ tapering as well as the
  648. choice of window function, however, applies to both input channels.
  649.  
  650. 3.1 Transformation
  651.  
  652.      Experimental data sampled by means of an analog-to-digital (A/D) converter
  653. typically results in data files containing an array of two-byte integer
  654. values.  This is due to the fact that a two-byte integer is capable of
  655. representing numbers in a range from -32768 to 32767.  This range is sufficient
  656. for 12, 14 and 16-bit converters and is used to approximate the magnitude of an
  657. analog voltage at a given instant of time.  This voltage is constrained to lie
  658. within a specified input voltage range which may or may not be programmable and
  659. which is particular to the A/D converter used.  Before proceeding to the
  660. spectral calculation, the integer input data must be transformed back into
  661. voltages using the scale factor appropriate for the input voltage range of the
  662. A/D converter used.
  663.  
  664.      During development of this routine, a 12-bit A/D converter was used which
  665. was capable of digitizing three different bipolar voltage ranges: -1V to 1V,
  666. -5V to 5V and -10V to 10V.  The use of 12 bits allows integer values ranging
  667. from -2048 to 2047 for a total of 4096 digital levels to be used to quantize
  668. each of the above input voltage ranges.  The appropriate scale factors for
  669. conversion of the integer data back into voltages are given by
  670.  
  671.  
  672. [EQUATION "center [2 #3 V] over [4096 #3 units] #4 , #4 [10 #3 V] over [4096 #3
  673.  
  674.  
  675.  
  676. respectively.  The user may choose from one of these scale factors or may enter
  677. an alternative scale factor from the keyboard.  The routine first prompts the
  678. user with:
  679.  
  680. Transform into (V)oltages or into (O)ther quantity
  681. or read (R)eal data which is already transformed :
  682.  
  683. If the input data consists of floating-point values, then the letter R should
  684. be entered, and the routine skips the rest of the transformation operation.
  685. For integer input data, the user responds with V for transformation into
  686. voltages, or O for voltage transformation followed by an additional
  687. transformation into a second dimensional quantity; the following prompt is then
  688. displayed:
  689.  
  690. Enter VOFST 1) 10/4096, 2) 20/4096, 3) 2/4096 or 4) other :
  691.  
  692. To this prompt, the user responds with a digit (1-4) indicating the desired
  693. scale factor for voltage transformation.  Selection of item (4) leads to the
  694. prompt:
  695.  
  696. Enter VOFST :
  697.  
  698. and, at this point, the user enters a floating-point number representing the
  699. desired scale factor.
  700.  
  701.      The input data will now be converted back into voltages using the scale
  702. factor specified above.  Since the analog voltage sampled by the A/D converter
  703. often comes from a transducer, which measures some dimensional quantity and
  704. then converts it to a voltage signal, provision for transforming the digitized
  705. input voltages back into the original transduced quantity is included.
  706. Knowledge of calibration data for the particular transducer is required for
  707. this transformation, and the calibration curve may be linear, quadratic,
  708. exponential, etc.  It was impossible during development of the code to
  709. anticipate all forms that the calibration curve might take; therefore, a
  710. polynomial fit was decided upon in hopes that it would satisfy the calibration
  711. requirements of most users.  The polynomial may consist of terms up to fourth
  712. degree; however, lower degree polynomial representations may be used by setting
  713. the coefficient for the appropriate term to zero.  The conversion from a
  714. voltage into a velocity, say, for each data point is carried out using
  715.  
  716.  
  717. [EQUATION "center u sub n #3#3 = #3#3 b sub 0 #3 + #3 b sub 1 v sub n #3 + #3 b
  718.  
  719.  
  720.  
  721. where  [EQUATION "b sub 0", Position:In Text]  through
  722. [EQUATION "b sub 4", Position:In Text]  are the five calibration coefficients,
  723. [EQUATION "v sub n", Position:In Text]  is the
  724. [EQUATION "nth", Position:In Text]  data point of the current record which has
  725. just been transformed into a velocity as described above and
  726. [EQUATION "u sub n", Position:In Text]  is the resulting
  727. [EQUATION "nth", Position:In Text]  velocity value.  The coefficients necessary
  728. to complete the transformation must be included in a suitable format in
  729. coefficient data files which are then read by the routine; instructions for the
  730. creation of these coefficient data files are contained in section 2.4.
  731.  
  732.      An alternative to the transformation operations described herein is also
  733. available.  The user may transform the original integer data from the A/D
  734. converter by means of his own program into floating-point data which can then
  735. be read by this routine.  The floating-point input data files must conform to
  736. the structure set forth in section 2.  The routine then skips the
  737. transformations described above and proceeds to the calculation of the mean and
  738. root-mean-square (rms) values of each data record and averaged values for the
  739. file.
  740.  
  741.      Summarizing then, the spectrum routine begins by reading in an input data
  742. file.  If this file consists of integers, then these integers are transformed
  743. to voltages using a voltage transformation factor (VOFST) selected by the
  744. user.  Optionally, these voltages can be further transformed into some other
  745. dimensional quantity.  If the input data file contains floating-point numbers,
  746. then the routine assumes that any transformation of the input data has already
  747. been applied by the user.  As the input data is read in by the spectrum
  748. routine, record by record, the mean and rms values of each record are
  749. calculated and displayed on the screen at run-time.  After all records of the
  750. input file have been read, the mean and rms values for each record are averaged
  751. to obtain values which are representative of the entire file.  These averaged
  752. mean and rms quantities are also displayed on the screen at run-time.  The
  753. spectrum routine then proceeds to the various data preparation operations
  754. discussed in the next section.  Note that the averaged mean and rms values for
  755. the file are calculated a second time later on in the program as a result of
  756. the spectral computation and are also displayed on the screen.  Theoretically,
  757. these two sets of values should be identical and serve as a check on the
  758. accuracy of the spectral computation.  However, if any of the data preparation
  759. operations to be discussed next are applied to the data to improve the accuracy
  760. of the spectral computation, the two sets of mean and rms values may not
  761. exactly match.  This is due to the fact that the data preparation operations
  762. change the input data.  The first set of mean and rms values are calculated
  763. prior to the data preparation operations, and the second set are computed from
  764. spectral density calculations which occur subsequent to the data preparation
  765. procedures.
  766.  
  767. 3.2 Mean Removal
  768.  
  769.      For calculation of spectral quantities, it is common to remove the mean
  770. value from the input data.  Both this operation and the trend removal operation
  771. described in the next section may be used for the removal of the mean from the
  772. sample data.  Trend removal is not always desirable; for that reason a separate
  773. operation to remove the mean is needed and is described here.  The mean value
  774. for each record of data in the input file is calculated from
  775.  
  776.  
  777. [EQUATION "center x bar #3#3 = #3#3 1 over N #3 sum below [n=1] above N #3 x
  778. sub
  779.  
  780.  
  781.  
  782. where  [EQUATION "x sub n", Position:In Text]  is defined as in equation 1.1;
  783. for convenience, and to reduce the algebra in the derivations in this section,
  784. [EQUATION "n", Position:In Text]  is defined such that
  785. [EQUATION "n #3#3 = #3#3 1,2, ... , N ", Position:In Text] , and the initial
  786. point of the record  [EQUATION "t sub 0", Position:In Text]  is set to zero.
  787. If  [EQUATION "y sub n", Position:In Text]  is used to represent the data with
  788. zero mean, then this quantity is computed from
  789.  
  790.  
  791. [EQUATION "center y sub n #3#3 = #3#3 x sub n #3#3 - #3#3 x bar right #R(3.4)"]
  792. [PAGE BREAK]
  793.  
  794. 3.3 Removal of Linear Trend
  795.  
  796.      As recommended by Bendat and Piersol (1986), a linear trend removal
  797. operation has been included in this routine.  This operation is designed to
  798. remove low frequency components in the data with a period longer than the
  799. record length  [EQUATION "T #3 = #3 N Delta t", Position:In Text] .  These low
  800. frequency trends can significantly distort spectral data; however, trend
  801. removal should only be performed if instrumentation drift or other sources of
  802. trends are expected.  Use of trend removal when no trends are present can
  803. introduce small contributions to the spectral density at frequencies on the
  804. order of the reciprocal of the record length.
  805.  
  806.      This operation is accomplished by fitting a straight line through the data
  807. using the least squares fit method.  The values calculated from this fit are
  808. then subtracted from the original data to yield data with zero mean and with no
  809. frequency components smaller than  [EQUATION "1 #1 / #1 T", Position:In Text]
  810. where  [EQUATION "T", Position:In Text]  is the record length.  Let
  811. [EQUATION "x tilde", Position:In Text]  be a first degree polynomial fit to the
  812. original data  [EQUATION "x sub n", Position:In Text]  (defined as in equation
  813. 1.1) where  [EQUATION "x tilde", Position:In Text]  is given by
  814.  
  815.  
  816. [EQUATION "center x tilde sub n #3#3 = #3#3 b sub 0 #3#3 + #3#3 b sub 1 #1 (n
  817. De
  818.  
  819.  
  820.  
  821. and with  [EQUATION "b sub 0", Position:In Text]  and
  822. [EQUATION "b sub 1", Position:In Text]  defined as
  823.  
  824.  
  825. [EQUATION "center #^ b sub 0 #3#3 = #3#3 [2 #1 (2N #3 + #3 1) #1 sum below
  826. [n=1]
  827.  
  828.  
  829.  
  830. Let  [EQUATION "y sub n", Position:In Text]  represent the detrended data;
  831. these data are obtained from the following difference
  832.  
  833.  
  834. [EQUATION "center y sub n #3#3 = #3#3 x sub n #3#3 - #3#3 x tilde sub n right
  835. #R
  836.  
  837.  
  838.  
  839. 3.4 Filtering
  840.  
  841.      The filtering operations incorporated in this routine were added to allow
  842. the user to pass only desired frequencies in the input data on to the spectral
  843. calculation.  Four recursive (infinite impulse response) Butterworth digital
  844. filters for filtering in the time domain have been included for this purpose:
  845. lowpass, highpass, bandpass and bandstop (notch).  A short discussion of
  846. digital filtering in the time domain including a summary of the particular
  847. filters used in this routine and instructions for their use follows.  Note
  848. however that filtering may be applied not only in the time domain but also in
  849. the frequency domain.  When filtering in the frequency domain, the input data
  850. record is Fast Fourier Transformed, then the FFT output is multiplied by a
  851. filter function, [EQUATION "H(f)", Position:In Text] ; if required, an inverse
  852. FFT could be performed to get the filtered data back into the time domain.
  853. Frequency domain filtering may perhaps be implemented in a future version of
  854. this program.
  855.  
  856.      Consider a set of discrete input values
  857. [EQUATION "x sub n", Position:In Text]  defined as in equation 1.1.  Digital
  858. filtering involves a computing algorithm in which a set of filtered values
  859. [EQUATION "y sub n", Position:In Text]  is produced as a result of operating on
  860. the inputs  [EQUATION "x sub n", Position:In Text] .  For the filters included
  861. in this routine, this is a linear operation.  Digital filters can generally be
  862. categorized as recursive or nonrecursive; if the formula for
  863. [EQUATION "y sub n", Position:In Text]  contains only input terms
  864. [EQUATION "x sub n", Position:In Text] , then the filter is termed
  865. nonrecursive.  The general form of the linear nonrecursive algorithm is given
  866. by
  867.  
  868.  
  869. [EQUATION "center y sub n #3#3 = #3#3 sum below [m #3 = #3 - #1 M] above M b
  870. sub
  871.  
  872.  
  873.  
  874. where  [EQUATION "b sub m", Position:In Text]  are the coefficients of the
  875. transformation.  For values of  [EQUATION "m #3 < #3 0", Position:In Text] ,
  876. the above algorithm requires future values of the signal
  877. [EQUATION "x(t)", Position:In Text] ; this can cause a realizibility problem in
  878. analog systems, but can be accomplished in digital systems where, in many
  879. cases, the future values of  [EQUATION "x(t)", Position:In Text]  can be stored
  880. in advance.  A recursive filter is one in which previously filtered values such
  881. as  [EQUATION "y sub [n-1]", Position:In Text] ,
  882. [EQUATION "y sub [n-2]", Position:In Text] , etc. appear explicitly in the
  883. algorithm for  [EQUATION "y sub n", Position:In Text] .  For recursive filters,
  884. the above equation is modified to include past values of the filtered output
  885. [EQUATION "y(t)", Position:In Text]  as follows:
  886.  
  887.  
  888. [EQUATION "center y sub n #3#3 = #3#3 sum below [m #3 = #3 - #1 M] above M b
  889. sub
  890.  
  891.  
  892.  
  893. The transfer function  [EQUATION "H(f)", Position:In Text]  for the filter is
  894. related to the coefficients  [EQUATION "a sub m", Position:In Text]  and
  895. [EQUATION "b sub m", Position:In Text]  by
  896.  
  897.  
  898. [EQUATION "center H(f) #3#3 = #3#3 [sum below [m #3 = #3 - #1 M] above M b sub
  899. m
  900.  
  901.  
  902.  
  903. This equation tells how to determine  [EQUATION "H(f)", Position:In Text]  from
  904. the coefficients  [EQUATION "a sub m", Position:In Text]  and
  905. [EQUATION "b sub m", Position:In Text] .  However, filter design requires the
  906. inverse problem: how to obtain a suitable set of coefficients based upon
  907. knowledge of a desired filter transfer function.  A variety of techniques exist
  908. to solve this problem, and the interested reader is referred to Stearns (1975)
  909. for a lengthy discussion of the matter.  The transfer function discussed above
  910. is more commonly expressed in terms of the variable
  911. [EQUATION "z", Position:In Text]  where
  912.  
  913.  
  914. [EQUATION "center z #3#3 == #3#3 e super [i 2 pi f Delta t] right #R(3.12)"]
  915.  
  916.  
  917. For recursive filters,  [EQUATION "H(z)", Position:In Text]  is a rational
  918. function of  [EQUATION "z", Position:In Text] .  It seems that rational
  919. functions are particular good at fitting functions with sharp edges; most
  920. filter functions are in this category.  The filters contained in this routine
  921. are modified versions of FORTRAN subroutines which originally appeared in
  922. Stearns (1975).  The order of the filter is determined by the number of
  923. cascaded stages that are used; a filter of order
  924. [EQUATION "P", Position:In Text]  will require
  925. [EQUATION "P #1 / #1 2", Position:In Text]  cascaded stages.  The transfer
  926. functions,  [EQUATION "H sub k #1 (z)", Position:In Text] , for the
  927. [EQUATION "kth", Position:In Text]  stage for each filter, and the recursive
  928. algorithms required to implement those transfer functions are given below.
  929.  
  930.  
  931.  
  932. [EQUATION "center #^ H sub k #1 (z) #3#3 = #3#3 [A sub k #1 (z super 2 #3 + #3
  933. 2
  934.  
  935.  
  936.  
  937. Note that the quantity  [EQUATION "K", Position:In Text]  in equation 3.16
  938. above is a constant which is the same for all stages of the notch filter.  The
  939. other coefficients,  [EQUATION "A sub k", Position:In Text]  through
  940. [EQUATION "E sub k", Position:In Text] , are a more compact notation for the
  941. [EQUATION "a sub m", Position:In Text]  and
  942. [EQUATION "b sub m", Position:In Text]  values for each stage
  943. [EQUATION "k", Position:In Text] .  In general,
  944. [EQUATION "A sub k", Position:In Text]  through
  945. [EQUATION "E sub k", Position:In Text]  change from stage to stage and are
  946. evaluated from complicated expressions which the interested reader may find in
  947. the source code.
  948.  
  949.      To use these filters, the user selects the desired filter type and enters
  950. the critical (-3 dB) frequency for the low and highpass filters.  For the
  951. bandpass and bandstop filters, two critical frequencies must be specified.  The
  952. number of filter sections to cascade must also be specified.  The order of the
  953. filter is twice the number of cascaded sections.  As the order of the filter is
  954. increased, the transfer function for the filter becomes sharper and more
  955. closely approximates the ideal; however, the amount of computation time is also
  956. significantly increased.  A good starting point may be to use five cascaded
  957. sections (tenth order); this is a reasonable trade-off between accuracy and
  958. computational efficiency.  These filters work well when the input data is not
  959. deterministic; however, unlike nonrecursive filters, recursive filters can
  960. become unstable and produce an output which grows exponentially.  This has been
  961. observed in a few rare instances during testing of this program and, so far,
  962. has been found to occur only when the input data has been a perfect
  963. computer-generated sinusoid.  The user should be aware of this limitation.
  964. [PAGE BREAK]
  965.  
  966. 3.5 Tapering
  967.  
  968.      The tapering option has been added to the routine as a grooming operation
  969. in order to improve the resulting spectral density estimates.  A wide variety
  970. of window functions may be found in the literature including extended
  971. discussions concerning their performance characteristics.  See, for example,
  972. Bendat and Piersol (1986) and Press, et al. (1986).  Rather than repeat these
  973. long discussions here, a brief summary of the need for tapering will be
  974. followed by a description of the window functions available for use with this
  975. routine.
  976.  
  977.      As discussed earlier in regard to equation 1.1, the data processed by this
  978. routine is in the form of a finite set of samples
  979. [EQUATION "x sub n", Position:In Text]  of the continuous signal
  980. [EQUATION "x(t)", Position:In Text]  which exists for a time
  981. [EQUATION "T #3 = #3 N #1 Delta t", Position:In Text] .  Now, suppose that
  982. [EQUATION "x(t)", Position:In Text]  is a finite portion of a continuous
  983. signal  [EQUATION "v(t)", Position:In Text]  which is of unlimited extent in
  984. time.  Then,  [EQUATION "x(t)", Position:In Text]  can be considered to be the
  985. product of  [EQUATION "v(t)", Position:In Text]  and a rectangular window
  986. function  [EQUATION "w(t)", Position:In Text]
  987.  
  988. [EQUATION "center x(t) #3#3 = #3#3 w(t) #3 v(t) right #R(3.17)"]
  989.  
  990.  
  991. where
  992.  
  993. [EQUATION "center w(t) #3#3 = #3#3 #( { stack left [[ 1 #4#4 0 <= t <= T] [ 0
  994. #4
  995.  
  996.  
  997.  
  998. A plot of the rectangular (square) window function
  999. [EQUATION "w(t)", Position:In Text]  is shown in figure 3.1 where, for
  1000. convenience,  [EQUATION "T", Position:In Text]  is chosen to equal one.  The
  1001. computation of spectral density estimates for
  1002. [EQUATION "x(t)", Position:In Text]  involves the calculation of the Fourier
  1003. transform of  [EQUATION "x(t)", Position:In Text]  which is equivalent to the
  1004. Fourier transform of the product of  [EQUATION "w(t)", Position:In Text]  and
  1005. [EQUATION "v(t)", Position:In Text] .  A theorem from Fourier analysis relates
  1006. the Fourier transform of a product of two functions in time to the convolution
  1007. of the transforms of these functions.  In other words, the following is a
  1008. Fourier transform pair:
  1009.  
  1010.  
  1011. [EQUATION "center w(t) #3 v(t) #3#3 <==> #3#3 W(f) #3 * #3 V(f) right
  1012. #R(3.19)"]
  1013.  
  1014.  
  1015.  
  1016. where
  1017.  
  1018. [EQUATION "center W(f) #3 * #3 V(f) #3#3 = #3#3 int sub [#3 - infinity] super
  1019. [i
  1020.  
  1021.  
  1022.  
  1023. The spectral density of interest would be exact if the transform
  1024. [EQUATION "V(f)", Position:In Text]  could be calculated.  Instead,
  1025. [EQUATION "X(f) #3 = #3 W(f) #3 * #3 V(f)", Position:In Text]  is the quantity
  1026. which is, in fact, calculated.  This problem then is seen to be directly
  1027. related to the finite length of the data to be transformed and to the fact that
  1028. the data is sharply truncated at each end of the time record.  A plot of the
  1029. modulus of the Fourier transform of the rectangular window function,
  1030. [EQUATION "W(f)", Position:In Text] , may be found in figure 3.2 and is defined
  1031. as[PAGE BREAK]
  1032.  
  1033.                   [WHITESPACE 0.25 in, Place All on Next Page]
  1034.  
  1035.  
  1036.                         [PICTURE FIG31.CGM, Scale:0.800]
  1037.  
  1038.                  Figure 3.1  Window functions available for tapering the data
  1039.  
  1040.  
  1041.  
  1042.  
  1043.                         [PICTURE FIG32.CGM, Scale:0.800]
  1044.  
  1045.                Figure 3.2  Normalized amplitude of Fourier transform of window
  1046.                              functions[PAGE BREAK]
  1047.  
  1048.  
  1049. [EQUATION "center W(f) #3#3 = #3#3 [sin #1 pi f T] over [pi f] #3#3 e super [-i
  1050.  
  1051.  
  1052.  
  1053. Again, for plotting convenience,  [EQUATION "T", Position:In Text]  is chosen
  1054. to equal one.  This function is characterized by a large main lobe with smaller
  1055. side lobes which slowly decrease in size.  The ideal window function would be a
  1056. delta function; that is, an infinitely thin main lobe with no side lobes at
  1057. all.  As  [EQUATION "W(f)", Position:In Text]  is convolved with
  1058. [EQUATION "V(f)", Position:In Text] , information at frequencies well separated
  1059. from the main lobe can leak into the calculation and significantly distort the
  1060. resulting spectra.  The large amplitude sidelobes need to be reduced to
  1061. suppress this problem.
  1062.  
  1063.      This is accomplished by multiplying the original data by a window function
  1064. which tapers the time history at the beginning and end of the record to remove
  1065. the discontinuities there.  The tapering functions included in this routine are
  1066. the most commonly used ones, and the choice of a particular function requires a
  1067. trade-off between the thickness of the main lobe (resolving power) and the size
  1068. of the side lobes.  The following window functions (the subscripts merely
  1069. indicate the name of the window) may be selected:
  1070.  
  1071.  
  1072.  
  1073.  
  1074. [EQUATION "center #^ w sub h (t) #3#3 = #3#3 #( { stack left [[ 1 over 2 #3 (1
  1075. #
  1076. [PAGE BREAK]
  1077.  
  1078. [EQUATION "center #^ w sub p (t) #3#3 = #3#3 #( { stack left [[ #4 1 #3 - #3 (|
  1079.  
  1080.  
  1081.  
  1082.  
  1083. These functions are plotted in figure 3.1.  The moduli of the Fourier
  1084. transforms for each of the above windows are plotted in figure 3.2 and are
  1085. normalized by their value at  [EQUATION "f #3 = #3 0", Position:In Text] .  The
  1086. fact that these transforms do not equal one for
  1087. [EQUATION "f #3 = #3 0", Position:In Text]  implies that the resulting spectral
  1088. estimates would be reduced in magnitude upon application of one of these
  1089. windows.  To avoid this problem, the appropriate scale factor is computed by
  1090. the routine when any of these windows are selected and automatically applied to
  1091. the data before computing the spectral estimate in order to preserve the
  1092. correct amplitudes.  The Fourier transform for each of the above windows is
  1093. given below.
  1094.  
  1095.  
  1096.  
  1097. [EQUATION "center W sub h (f,T) #3#3 = #3#3 {#3#3 1 over 2 ( [sin #3 pi f T]
  1098. ove
  1099.  
  1100.  
  1101.  
  1102.  
  1103. [EQUATION "center W sub t (f,T) #3#3 #^ = #3#3 {#3#3 1 over 2 ( [sin #3 pi f T]
  1104.  
  1105.  
  1106.  
  1107.  
  1108. [EQUATION "center W sub w (f,T) #3#3 = #3#3 2 over [pi f T] #3#3 ( 1 over [ pi
  1109. f
  1110.  
  1111.  
  1112.  
  1113.  
  1114. [EQUATION "center W sub p (f,T) #3#3 = #3#3 1 over [pi f T] #3#3 ( 1 over [ pi
  1115. f
  1116.  
  1117.  
  1118.  
  1119.  
  1120. In equations 3.26 and 3.27 above
  1121. [EQUATION "f sub 1 #3 = #3 1 #1 / #1 T", Position:In Text] .  Recall that if
  1122. none of these windows are selected (no tapering), then the square window
  1123. defined in equation 3.18 and with a Fourier transform as defined in equation
  1124. 3.21 is implicitly used.  The most commonly used window function is the Hanning
  1125. window; the transform for this function has the smallest side lobes but also
  1126. has the widest main lobe.  Also shown is a window which provides a cosine taper
  1127. for the first and last tenths of the data record, is one for the remainder of
  1128. the data record and is denoted by the name Tukey (also known as a 10% cosine
  1129. taper).  This window has been used by many researchers in the hopes that it
  1130. will throw away less of the data.  Examination of the modulus of the Fourier
  1131. transform for this window shows that it manages to narrow the main lobe a small
  1132. amount relative to the other windows, but it does this at the expense of large
  1133. side lobes that are nearly as large as that of the square window (no tapering
  1134. at all).
  1135.  
  1136.      A better way to throw away less of the data is to use any of the windows
  1137. available above and then to use overlapped processing techniques.  Before
  1138. describing overlapped processing, it is useful to review the procedure for the
  1139. calculation of spectra when no overlap is used.  The data are prepared
  1140. (detrended, filtered, etc.), and then the data are tapered.  The data are
  1141. tapered record by record and transformed to get the necessary spectra.  When
  1142. 50% overlapped processing is used, the tapering operation proceeds a bit
  1143. differently.  First, the initial record of the data is tapered.  Then, the
  1144. second half of the first record is grouped together with the first half of the
  1145. second record to form a new second record, and then this new record of data is
  1146. tapered.  Then, the two halves of the old second record form the new third
  1147. record, and this is then tapered.  Then, the second half of old second record
  1148. is grouped together with the first half of the old third record to form a new
  1149. fourth record which is then tapered.  This proceeds throughout the file until
  1150. [EQUATION "M", Position:In Text]  old records are processed creating exactly
  1151. [EQUATION "2M", Position:In Text]  new records.  The last grouping pairs the
  1152. second half of the old last record with the first half of the old first record
  1153. to form the new  [EQUATION "2Mth", Position:In Text]  record.  This last record
  1154. was included in order to simplify the code for this procedure.  Because the
  1155. [EQUATION "2Mth", Position:In Text]  record has a discontinuity at the
  1156. midpoint, this record should not be transformed.  However, simply removing this
  1157. record would require that an odd number of records be submitted to the FFT
  1158. code.  As pointed out earlier, the FFT routine has been designed such that it
  1159. transforms two records of data in one pass as a time-saving measure; this
  1160. requires (in the one channel case) that an even number of records be processed
  1161. by the FFT routine.  Therefore, the overlapping operation has not been
  1162. modified;  [EQUATION "2M", Position:In Text]  records are created from
  1163. [EQUATION "M", Position:In Text]  original records for both the one and two
  1164. channel cases.  These  [EQUATION "2M", Position:In Text]  records are then
  1165. submitted to the FFT subroutine and are transformed; but the results of the
  1166. [EQUATION "2Mth", Position:In Text]  record are discarded after the
  1167. transformation.  Summarizing, when overlapping is employed,
  1168. [EQUATION "2M", Position:In Text]  records are created and are then
  1169. transformed, but only the results from
  1170. [EQUATION "2M #3 - #3 1", Position:In Text]  records are actually used in the
  1171. final calculations.  To avoid discontinuities resulting from the use of
  1172. overlapping in any of the other  [EQUATION "2M #3 - #3 1", Position:In Text]
  1173. records, the  [EQUATION "M", Position:In Text]  original records must be
  1174. contiguous in time.  The data need not be contiguous from record to record if
  1175. overlapping is not employed.  The use of 50% overlapped processing doubles the
  1176. number of tapering and FFT operations; however, this will retrieve about 90% of
  1177. the stability lost due to the tapering operation and will decrease the
  1178. variability of the resulting estimate.
  1179.  
  1180.      Finally, tapering is best used when the input data are essentially random
  1181. data -- that is, not deterministic.  When this program was tested, input data
  1182. (both deterministic and random) with known spectral densities were used.  When
  1183. a sinewave was used for input, the power and amplitude spectra exhibited a
  1184. lower noise floor when no tapering was used.  On the other hand, when colored
  1185. noise (bandwidth limited white noise) was used for input, a substantial
  1186. improvement was evident in the output spectra when any of the four window
  1187. functions described above was used to taper the data.
  1188.  
  1189.                   ^SÿSpectrum Computation
  1190.  
  1191.      This section introduces the definitions of the discrete Fourier transform
  1192. and the various spectral density functions computed by this routine.  The means
  1193. by which these estimates are computed as well as the errors associated with the
  1194. calculation are discussed.  The need for additional code to adjust the value of
  1195. the computed phase angle of the cross-spectral density function is explained by
  1196. means of an example, and an explanation of the coherence function calculated by
  1197. this routine is given.
  1198.  
  1199. 4.1 Fast Fourier Transform
  1200.  
  1201.      Using the notation of Bendat and Piersol (1986), the Fourier transform of
  1202. a function  [EQUATION "x(t)", Position:In Text] , where
  1203. [EQUATION "x(t)", Position:In Text]  may be real or complex-valued, is given by
  1204.  
  1205.  
  1206. [EQUATION "center X(f) #3#3 = #3#3 int super [infinity] sub [- infinity] #3
  1207. x(t)
  1208.  
  1209.  
  1210.  
  1211. This definition is not particularly useful for experimentally derived data
  1212. which exist for only a finite time interval.  For this reason, one usually
  1213. employs a finite-range transform over the interval
  1214. [EQUATION "0 <= t <= T", Position:In Text] , and this transform is defined by
  1215.  
  1216.  
  1217. [EQUATION "center X (f,T) #3#3 = #3#3 int super T sub [#3 0] #3 x (t) #3 e
  1218. super
  1219.  
  1220.  
  1221.  
  1222. As in equation 1.1, assume that each record of the input data file consists of
  1223. [EQUATION "N", Position:In Text]  samples of
  1224. [EQUATION "x(t)", Position:In Text]  which have been obtained at equally spaced
  1225. points in time with spacing  [EQUATION "Delta t", Position:In Text] .  Note
  1226. that  [EQUATION "t sub 0", Position:In Text]  has been set equal to zero for
  1227. convenience.  Then, each record contains the values
  1228. [EQUATION "x sub n", Position:In Text]  where
  1229.  
  1230.  
  1231. [EQUATION "center x sub n #3#3 = #3#3 x(n Delta t) #4#4 #R[for] #4 n #3 = #3
  1232. 0,1
  1233.  
  1234.  
  1235.  
  1236. Now, the finite-range transform defined in equation 4.2 can be written in
  1237. discrete form as
  1238.  
  1239.  
  1240. [EQUATION "center X(f,T) #3#3 = #3#3 Delta t #3#3 sum below [n=0] above [N-1]
  1241. #3
  1242.  
  1243.  
  1244.  
  1245. Since only  [EQUATION "N", Position:In Text]  input values of
  1246. [EQUATION "x sub n", Position:In Text]  are used in the computation of the
  1247. transform,  only  [EQUATION "N", Position:In Text]  output values of
  1248. [EQUATION "X(f,T)", Position:In Text]  may be specified.  These are typically
  1249. chosen at the following discrete frequency values
  1250.  
  1251.  
  1252. [EQUATION "center f sub k #3#3 = #3#3 k over T #3#3 = #3#3 k over [N Delta t]
  1253. #3
  1254.  
  1255.  
  1256.  
  1257. Thus, the discrete form of the finite-range Fourier transform becomes
  1258.  
  1259.  
  1260. [EQUATION "center X(f sub k #1,T) #3#3 = #3#3 Delta t #3#3 sum below [n=0]
  1261. above
  1262.  
  1263.  
  1264.  
  1265. Although  [EQUATION "N", Position:In Text]  output values have been specified,
  1266. results are unique only out to
  1267. [EQUATION "k #3 = #3 N #1 / #1 2", Position:In Text] ; this is a result of the
  1268. symmetry of the Fourier transform for real input values.  Thus, the highest
  1269. frequency that can be resolved for a sampling rate of
  1270. [EQUATION "1 #1 / #1 Delta t", Position:In Text]  samples per second is the
  1271. Nyquist frequency given by
  1272.  
  1273.  
  1274. [EQUATION "center f sub [N over 2] #3#3 = #3#3 f sub c #3#3 = #3#3 1 over [2 #1
  1275.  
  1276.  
  1277.  
  1278. which occurs for  [EQUATION "k #3 = #3 N #1 / #1 2", Position:In Text] .  To
  1279. compute the  [EQUATION "X sub k", Position:In Text]  values in equation 4.6
  1280. requires  [EQUATION "N super 2", Position:In Text]  complex multiply-add
  1281. operations for each record of the data file; note that 1 complex multiply-add
  1282. operation is equivalent to 4 real multiply-adds.  This can be quite a
  1283. formidable computational task as  [EQUATION "N", Position:In Text]  becomes
  1284. large.  Fortunately, several algorithms for reducing the complexity and
  1285. increasing the speed of the computation exist and are known collectively as
  1286. fast Fourier transforms (FFT).  Rather than discuss these algorithms in detail,
  1287. the reader is referred to the discussions that may be found in the references.
  1288. The FFT algorithm used here employs a technique known as time decomposition
  1289. with input bit reversal.  The kernel of this algorithm was taken from
  1290. Stearns (1975).  The simplest implementation of this algorithm calls for
  1291. [EQUATION "N", Position:In Text]  to be a power of 2.  This is required in this
  1292. routine, and if necessary, each record of the input data file should be padded
  1293. with zeros at the end to satisfy this requirement.
  1294.  
  1295.      The FFT algorithm used in this routine is designed to handle the general
  1296. case where  [EQUATION "x(t)", Position:In Text]  is a complex-valued function;
  1297. that is, the input data which is passed to the FFT subroutine consists of two
  1298. arrays: one containing the real parts and the other containing the imaginary
  1299. parts.  However, experimentally sampled random time series data are
  1300. real-valued.  When the FFT of a purely real-valued function is computed,
  1301. certain symmetries in the resulting transform allow one to compute the FFTs for
  1302. two real-valued functions simultaneously by inserting one into the input array
  1303. of real parts and the other into the array of imaginary parts.  The trick is to
  1304. unscramble the individual transforms from the resulting computation.  This
  1305. speed improvement has been incorporated into this routine, but it places a
  1306. restriction on the input data files.  If the input data file to be processed by
  1307. SPECTRUM consists of one channel of sampled data, then the data file must
  1308. consist of an even number of records.  The reason for this is that input data
  1309. records are submitted to the FFT algorithm two at a time to obtain the speed
  1310. improvement discussed above.  If the input data file consists of two channels
  1311. of sampled data, then each record of the file is first decomposed into the two
  1312. separate channels, and these are then submitted to the FFT algorithm to be
  1313. simultaneously processed.  So, for the case of two channels of sampled data,
  1314. the input data file may have an even or odd number of records.
  1315.  
  1316. 4.2 Autospectral (Power) Density
  1317.  
  1318.      The one-sided autospectral density function, defined for positive
  1319. frequencies only, is usually expressed as twice the amplitude of the Fourier
  1320. transform of the autocorrelation function as follows:
  1321.  
  1322.  
  1323. [EQUATION "center G sub [xx] (f) #3#3 = #3#3 2 #3 int super infinity sub [#3 -
  1324. i
  1325.  
  1326.  
  1327.  
  1328. where  [EQUATION "R sub [xx] (tau)", Position:In Text]  is the autocorrelation
  1329. function defined as
  1330.  
  1331.  
  1332. [EQUATION "center R sub [xx] (tau) #3#3 = #3#3 E #[ #3 x(t) #3 x(t + tau) #3 #]
  1333.  
  1334.  
  1335.  
  1336. and the notation E[ ] denotes the expected value operation.
  1337. [EQUATION "G sub [xx] (f)", Position:In Text]  is a real function of
  1338. [EQUATION "f", Position:In Text]  regardless of whether
  1339. [EQUATION "x(t)", Position:In Text]  is real or complex.  This calculation is
  1340. implemented in this routine using digital computing techniques employing finite
  1341. fast Fourier transforms of the original data records.  Using this method, the
  1342. autospectral density may be obtained from
  1343.  
  1344.  
  1345. [EQUATION "center G sub [xx] (f) #3#3 = #3#3 2 #3#3 lim below [T -> infinity]
  1346. #3
  1347.  
  1348.  
  1349.  
  1350. [EQUATION "| #3#3 |", Position:In Text]  denotes the modulus of a complex
  1351. quantity, and  [EQUATION "X (f,T)", Position:In Text]  is the finite Fourier
  1352. transform which is valid for the interval
  1353. [EQUATION "0 <= t <= T", Position:In Text]  and is calculated as in equation
  1354. 4.6.  If the input data file contains two channels of data, denoted as
  1355. [EQUATION "x(t)", Position:In Text]  and  [EQUATION "y(t)", Position:In Text] ,
  1356. then selection of the power spectral density option results in the computation
  1357. of  [EQUATION "G sub [xx] (f)", Position:In Text]  and
  1358. [EQUATION "G sub [yy] (f)", Position:In Text] .
  1359.  
  1360.      Specifically, the calculation proceeds by computing the FFT for each
  1361. record of the input data file, determining the modulus of the complex result,
  1362. squaring it and then saving the results to an array.  This is repeated for each
  1363. record; upon completion, the results are ensemble averaged to approximate the
  1364. expected value operation required in the definition.  The computation of an
  1365. expected value is needed to reduce the random error of the estimated
  1366. autospectral density function.  The number of records in the input data file
  1367. determines the number of members in the ensemble which will be averaged.  If
  1368. the number of records in the data file (before tapering) is denoted by
  1369. [EQUATION "n sub r", Position:In Text] , then the normalized random error of
  1370. the autospectral density estimate is given by
  1371.  
  1372.  
  1373. [EQUATION "center G sub [xx] (f) #3 : #4#4 epsilon #3#3 = #3#3 1 over [root[n
  1374. su
  1375.  
  1376.  
  1377.  
  1378. where the normalized random error is defined as a fractional quantity by
  1379. dividing the standard deviation of the estimate by the actual value estimated.
  1380. If the tapering operation is used, it will increase the variability of the
  1381. resulting estimate by an amount which depends upon the particular window
  1382. function chosen.  This increase in the variance of the estimate is, in the
  1383. worst case (Hanning), about two; but if the 50% overlap technique is also
  1384. employed, it will counteract this increase and will recover about 90% of the
  1385. variability caused by tapering.  Thus, the normalized random error calculated
  1386. from equation 4.11 will serve as a reasonably accurate estimate for both the no
  1387. taper and taper with overlap cases.  If tapering is used but overlapping is
  1388. not, then the variance is doubled and the normalized random error defined in
  1389. equation 4.11 should be multiplied by the square root of two.  The routine
  1390. computes the appropriate value of the normalized random error and displays it
  1391. on the screen at run-time.  As an example, consider an autospectral density
  1392. estimate computed from a data file with 100 original records which are then
  1393. overlapped and tapered to produce 199 records; this estimate will have a
  1394. normalized random error of 10%.  To reduce this error to 5%, the input data
  1395. file would have to contain 400 records.  There is no specific numerical limit
  1396. to the number of records that an input data file may contain; the spectrum
  1397. routine has successfully computed spectral densities for input data files with
  1398. 10,000 records.  However, data files with more than 100 records are usually
  1399. quite large. Furthermore, the spectrum routine must create temporary files
  1400. during computation, and the size of these files (depends upon the size of the
  1401. input data file) is often very large.  Reserving a sufficient amount of space
  1402. on the hard disk or on a RAM disk for these files is typically the limiting
  1403. factor on the number of records.
  1404.  
  1405.      The computation of a fast Fourier transform and power spectral density
  1406. function allows the calculation of the mean and root-mean-square (rms) values
  1407. of each record of the input time series.  The equation for the mean value of
  1408. each data record can be obtained by setting
  1409. [EQUATION "k #3 = #3 0", Position:In Text]  in equation 4.6.  One then obtains
  1410.  
  1411.  
  1412. [EQUATION "center x bar #3#3 = #3#3 X sub 0 over N #3#3 = #3#3 1 over N #3 sum
  1413. b
  1414.  
  1415.  
  1416.  
  1417. The mean-square value of each record can be computed from
  1418.  
  1419.  
  1420. [EQUATION "center R sub [xx] (0) #3#3 = #3#3 E #[ #3 x super 2 (t) #3 #] #3#3 =
  1421.  
  1422.  
  1423.  
  1424. The rms value is just the square root of this number.  The spectrum routine
  1425. calculates the mean and rms values of the input time series using this
  1426. procedure and reports them on the screen at run-time along with the appropriate
  1427. value of the normalized random error.
  1428.  
  1429. 4.3 Cross-spectral Density
  1430.  
  1431.      4.3.1 Calculation Procedure
  1432.  
  1433.      A one-sided cross-spectral density function
  1434. [EQUATION "G sub [xy] #1 (f)", Position:In Text]  may be defined in a manner
  1435. similar to equation 4.8; this quantity is, in general, complex and is given by
  1436.  
  1437.  
  1438. [EQUATION "center G sub [xy] (f) #3#3 = #3#3 2 #3 int super infinity sub [#3 -
  1439. i
  1440.  
  1441.  
  1442.  
  1443. The quantity  [EQUATION "R sub [xy] (tau)", Position:In Text]  is the cross
  1444. correlation function defined by
  1445.  
  1446.  
  1447. [EQUATION "center R sub [xy] (tau) #3#3 = #3#3 E #[ #3 x(t) #3 y(t + tau) #3 #]
  1448.  
  1449.  
  1450.  
  1451. The cross-spectral density may also be computed using fast Fourier transform
  1452. procedures and is the method adopted here.  The equivalent expression to
  1453. equation 4.10 for the one-sided cross-spectral density function is
  1454.  
  1455.  
  1456. [EQUATION "center G sub [xy] (f) #3#3 = #3#3 2 #3#3 lim below [T -> infinity]
  1457. #3
  1458.  
  1459.  
  1460.  
  1461. where the notation  [EQUATION "X super * (f,T)", Position:In Text]  is used to
  1462. represent the complex conjugate.  Alternatively, this can be expressed in polar
  1463. notation as
  1464.  
  1465.  
  1466. [EQUATION "center G sub [xy] #1 (f) #3#3 = #3#3 | G sub [xy] #1 (f) | #3 e
  1467. super
  1468.  
  1469.  
  1470.  
  1471. Note that this option may be selected only when the input data file contains
  1472. two channels of data, then, the magnitude and phase,
  1473. [EQUATION "| G sub [xy] #1 (f) |", Position:In Text]  and
  1474. [EQUATION "theta sub [xy] #1 (f)", Position:In Text]  respectively, are the
  1475. quantities which are calculated and then saved in the output file.
  1476.  
  1477.      As described above in the section on power spectral density calculation,
  1478. it is possible to compute the value of the autocorrelation function for
  1479. [EQUATION "tau #3 = #3 0", Position:In Text]  (the mean-square value) by
  1480. calculating the integral of the autospectral density function.  In a similar
  1481. manner one may compute the cross correlation function evaluated at
  1482. [EQUATION "tau #3 = #3 0", Position:In Text]  from
  1483.  
  1484.  
  1485. [EQUATION "center R sub [xy] #1 (0) #3#3 = #3#3 E #[ #3 x(t) #3 y(t) #3 #] #3#3
  1486.  
  1487.  
  1488.  
  1489. The spectrum routine calculates this quantity and displays it on the screen at
  1490. run-time.
  1491.  
  1492.      4.3.2 Adjustment of Phase Angle
  1493.  
  1494.      In order to clarify the need for additional code to adjust the values of
  1495. the phase angle  [EQUATION "theta sub [xy] (f)", Position:In Text] , an example
  1496. taken from Hess (1990) will be given which also serves to illustrate the use of
  1497. the cross spectral density function in general.  Specifically, a point
  1498. measurement of the vertical displacement of a compliant surface, responding to
  1499. the unsteady forcing of a fluid flow above the surface, was acquired; call this
  1500. displacement signal  [EQUATION "x(t)", Position:In Text] .  As
  1501. [EQUATION "x(t)", Position:In Text]  was measured, a second displacement signal
  1502. was simultaneously measured; call this second signal
  1503. [EQUATION "y(t)", Position:In Text] .  The locations on the compliant surface
  1504. of the measurement of  [EQUATION "x(t)", Position:In Text]  and
  1505. [EQUATION "y(t)", Position:In Text]  were as follows:  both were obtained on
  1506. the centerline of the rectangular compliant slab, and
  1507. [EQUATION "y(t)", Position:In Text]  was located 11.4 cm downstream of
  1508. [EQUATION "x(t)", Position:In Text] .  The fluid flow was turbulent; the
  1509. instantaneous streamwise component of velocity above the compliant surface
  1510. consisted of a small fluctuating quantity superimposed upon a larger mean
  1511. value.  A disturbance in the fluid flow caused a displacement of the compliant
  1512. surface which was measured at the upstream location and was recorded at time
  1513. [EQUATION "t", Position:In Text]  as  [EQUATION "x(t)", Position:In Text] .  As
  1514. the flow disturbance was convected downstream by the mean flow, the
  1515. displacement of the compliant surface also travelled downstream and was
  1516. measured at the downstream location as  [EQUATION "y(t+tau)", Position:In Text]
  1517.   where  [EQUATION "tau", Position:In Text]  was the time delay for the
  1518. disturbance to travel 11.4 cm.  Quantities of interest, then, are the
  1519. convection speed of the displacement fluctuation on the compliant surface as
  1520. well as the decrease in amplitude of this fluctuation as it decays.
  1521.  
  1522.      For this particular situation, the decay of the displacement field may be
  1523. modeled by the time delay problem, see Bendat and Piersol (1986).  This model
  1524. provides a method for determining the convection speed of the displacement
  1525. fluctuation.  Consider two zero-mean stationary random signals
  1526. [EQUATION "x(t)", Position:In Text]  and  [EQUATION "y(t)", Position:In Text]
  1527. where  [EQUATION "y(t)", Position:In Text]  is defined by
  1528.  
  1529.  
  1530.  
  1531. [EQUATION "center y(t) #3#3 = #3#3 alpha #1 x(t-tau sub 0) #3#3 + #3#3 n(t)
  1532. #3#3
  1533.  
  1534.  
  1535.  
  1536. The value  [EQUATION "alpha", Position:In Text]  is a constant attenuation,
  1537. [EQUATION "tau sub 0", Position:In Text]  is a constant time delay and
  1538. [EQUATION "n(t)", Position:In Text]  is uncorrelated, zero mean value noise at
  1539. the output.  This process is illustrated in figure 4.1.
  1540.  
  1541.                         [PICTURE FIG41.CGM, Scale:0.800]
  1542.  
  1543.                   Figure 4.1  Schematic for time delay problem
  1544.  
  1545.  
  1546. The cross-correlation of these two signals can be computed to be
  1547.  
  1548.  
  1549. [EQUATION "center R sub [xy] #1 (tau) #3#3 = #3#3 alpha #3 R sub [xx] #1 (tau -
  1550.  
  1551.  
  1552.  
  1553. Thus, the cross-correlation is an attenuated replica of the autocorrelation,
  1554. which is displaced in time by the amount
  1555. [EQUATION "tau sub 0", Position:In Text] .  Without going through all of the
  1556. details, a one-sided cross-spectral density function
  1557. [EQUATION "G sub [xy] #1 (f)", Position:In Text]  may also be computed; this
  1558. quantity is, in general, complex and for this problem is given by
  1559.  
  1560.  
  1561. [EQUATION "center G sub [xy] #1 (f) #3#3 = #3#3 alpha #3 G sub [xx] #1 (f) #3 e
  1562.  
  1563.  
  1564.  
  1565. Since the time delay  [EQUATION "tau sub 0", Position:In Text]  appears only in
  1566. the phase angle,  [EQUATION "theta sub [xy] #1 (f)", Position:In Text] , it can
  1567. be determined from measurement of the phase angle and by noting that it is a
  1568. linear function of the frequency with slope
  1569. [EQUATION "2 pi tau sub 0", Position:In Text] .  Summarizing then, a
  1570. cross-spectral density is computed for  [EQUATION "x(t)", Position:In Text]
  1571. and  [EQUATION "y(t)", Position:In Text] .  If the process can be modelled by
  1572. the time delay problem, then the modulus will be an attenuated replica of the
  1573. autospectral density,  [EQUATION "G sub [xx] (f)", Position:In Text] , and the
  1574. phase angle will be a linear function of the frequency with a slope given by
  1575. [EQUATION "2 pi tau sub 0", Position:In Text] .  A convection speed may then be
  1576. calculated from
  1577. [EQUATION "U sub c #3#3 = #3#3 11.4 over [tau sub 0]", Position:In Text]
  1578.   cm/sec.
  1579.  
  1580.      An example of this procedure is shown in figure 4.2.  The top graph shows
  1581. the autospectral density curve  [EQUATION "G sub [xx] (f)", Position:In Text]
  1582. and below it the modulus  [EQUATION "| G sub [xy] (f) |", Position:In Text]
  1583. for the corresponding cross-correlation; indeed, the bottom curve does appear
  1584. to be an attenuated copy of the first.  Note the substantial additional scatter
  1585. in the cross-spectral density estimate relative to that for the autospectral
  1586. density estimate at the higher frequencies.  The normalized random error
  1587.  
  1588.                         [PICTURE FIG42.CGM, Scale:0.800]
  1589.  
  1590.                      Figure 4.2  Cross-spectral density modulus example
  1591.  
  1592.  
  1593. for the cross-spectral density estimate turns out to be a function of frequency
  1594. unlike that for the autospectral density estimate.  A discussion of the means
  1595. for estimating this error is given in a later section.
  1596.  
  1597.      Figure 4.3 displays the computed phase angle expressed in radians.  With
  1598. the data presented in this form, it is difficult to fit the data with a least
  1599. squares fit in order to determine the slope, and therefore,
  1600. [EQUATION "tau sub 0", Position:In Text] .  This difficulty may be traced to
  1601. the fact that an inverse tangent must be computed in order to calculate the
  1602. value of the phase angle.  The FORTRAN intrinsic function ATAN2 returns a value
  1603. for the inverse tangent, but forces the result to lie in the range
  1604. [EQUATION "- pi #3 <= #3 result #3 <= #3 pi", Position:In Text] .  However, the
  1605. phase angle function is periodic with period
  1606. [EQUATION "2 pi", Position:In Text] .  Using this fact, additional code may be
  1607. used to straighten out the curve by adding integer multiples of
  1608. [EQUATION "2 pi", Position:In Text]  as required.  Figure 4.4 shows the
  1609. adjusted values of the phase angle and a least squares fit to the slope.  The
  1610. calculated values of  [EQUATION "tau sub 0", Position:In Text]  and
  1611. [EQUATION "[U sub c] #1 / #1 [U sub infinity]", Position:In Text] , where
  1612. [EQUATION "U sub [infinity]", Position:In Text]  is the mean flow speed far
  1613. above the compliant surface, are given on the plot.  The scatter in the phase
  1614. angle data becomes large at a frequency for which the energy in the signal is
  1615. about two decades below the peak value.  Computed values of the convection
  1616. speed using this method vary by less than 2% from those obtained using an
  1617. alternative method.
  1618.  
  1619.      The phase angle data can be adjusted manually, but this is a tedious and
  1620. time-consuming procedure.  Instead, the spectrum routine automatically computes
  1621. both the original values of the phase angle as well as the adjusted values of
  1622. the phase angle when the cross spectral density and the coherence function are
  1623. calculated.  Note that the relationships derived in equations 4.21 apply only
  1624. when equation 4.19 may be used as a model for the data.  Therefore, both sets
  1625. of phase angle data, unadjusted and adjusted values, are stored to the output
  1626. file and made available to the user.  The task of adjusting these phase angle
  1627. values, while conceptually simple, is somewhat tricky to program.  A
  1628. description of the technique follows.
  1629.  
  1630.      The standard deviation of the phase angle estimate as a function of
  1631. frequency is computed when the coherence function is computed (this will be
  1632. explained in the section on error estimates).  The average of a moving window
  1633. of  [EQUATION "NSD", Position:In Text]  values of this standard deviation is
  1634. computed and checked against a threshold value given by
  1635. [EQUATION "SDLIM", Position:In Text] .  If the average standard deviation is
  1636. too high, then the phase angle points are considered to be essentially random
  1637. and no further attempts to adjust the values are made.  Thus, when this
  1638. condition occurs, the remaining phase angle values are kept the same as the
  1639. original values (not adjusted).  When the moving average of the standard
  1640. deviation is less than  [EQUATION "SDLIM", Position:In Text] , then adjustment
  1641. may take place as follows.  A straight line is fit to a moving window of
  1642. [EQUATION "NPTS", Position:In Text]  values of the original phase angle data
  1643. using a least squares fit.  The coefficients of this fit are used to guess the
  1644. next value of the phase angle; if the actual value of the next phase angle data
  1645. point differs from the guessed value by an amount greater than
  1646. [EQUATION "pi", Position:In Text]  radians, then multiples of
  1647. [EQUATION "2 pi", Position:In Text]  radians are added to (or subtracted from)
  1648. the actual value until the difference between the actual and guessed values is
  1649. less than  [EQUATION "pi", Position:In Text]  radians.  The procedure continues
  1650. to adjust subsequent values of the phase angle until the moving average of the
  1651. standard deviation exceeds  [EQUATION "SDLIM", Position:In Text] .  This
  1652. portion of the code contains three adjustable parameters:
  1653. [EQUATION "NSD #3 = #3 7", Position:In Text] ,
  1654. [EQUATION "NPTS #3 = #3 7", Position:In Text]  and
  1655. [EQUATION "SDLIM =70.0 degree", Position:In Text] .  These values have been
  1656. selected by trial and error to yield the best response for the data most often
  1657. processed by the author.  Other values may be chosen by changing the numbers in
  1658. the appropriate PARAMETER statement at the beginning of the code.  Note that
  1659. [EQUATION "NSD", Position:In Text]  and [EQUATION "NPTS", Position:In Text]
  1660. must be chosen such that
  1661.  
  1662.  
  1663. [EQUATION "center NSD #3#3 <= #3#3 2 #3 NPTS #3#3 - #3#3 1 right #R(4.22)"]
  1664.  
  1665.  
  1666. is satisfied.  This adjustment procedure seems to work reasonably well for most
  1667. situations encountered by the author; however, some manual adjustment of values
  1668. may still be required in some circumstances.[PAGE BREAK]
  1669.  
  1670.                   [WHITESPACE 0.4 in, Place All on Next Page]
  1671.  
  1672.                         [PICTURE FIG43.CGM, Scale:0.800]
  1673.  
  1674.                                Figure 4.3  Phase angle example
  1675.  
  1676.                   [WHITESPACE 0.25 in, Place All on Next Page]
  1677.  
  1678.                         [PICTURE FIG44.CGM, Scale:0.800]
  1679.  
  1680.                     Figure 4.4  Phase angle - adjusted values[PAGE BREAK]
  1681.  
  1682.      4.3.3 Coherence Function
  1683.  
  1684.      The coherence function, also known as the coherency squared function is
  1685. defined by
  1686.  
  1687.  
  1688. [EQUATION "center gamma super 2 sub [xy] (f) #3#3 = #3#3 [ | G sub [xy] (f) |
  1689. su
  1690.  
  1691.  
  1692.  
  1693. where
  1694. [EQUATION "0 #3 <= #3 gamma super 2 sub [xy] (f) #3 <= #3 1", Position:In Text]
  1695.   for all  [EQUATION "f", Position:In Text] .  This function is analogous to
  1696. the square of the more well known correlation coefficient function given by
  1697.  
  1698.  
  1699. [EQUATION "center rho sub [xy] (tau) #3#3 = #3#3 [R sub [xy] (tau)] over [ #[ R
  1700.  
  1701.  
  1702.  
  1703. where  [EQUATION "-1 #3 <= #3 rho sub [xy] (tau) #3 <= #3 1", Position:In Text]
  1704.   for all values of  [EQUATION "tau", Position:In Text] .  As described by
  1705. Bendat and Piersol (1986), the function
  1706. [EQUATION "rho sub [xy] (tau)", Position:In Text]  measures the degree of
  1707. linear dependence between  [EQUATION "x(t)", Position:In Text]  and
  1708. [EQUATION "y(t)", Position:In Text]  for a displacement of
  1709. [EQUATION "tau", Position:In Text]  in  [EQUATION "y(t)", Position:In Text]
  1710. relative to  [EQUATION "x(t)", Position:In Text] .  Similarly, for linear
  1711. systems, the function  [EQUATION "gamma super 2 sub [xy] (f)", Position:In
  1712. Text]
  1713.   measures the fractional portion of the mean square value at the output
  1714. [EQUATION "y(t)", Position:In Text]  that is contributed by the input
  1715. [EQUATION "x(t)", Position:In Text]  at frequency
  1716. [EQUATION "f", Position:In Text] .  On the other hand, the quantity
  1717. [EQUATION "#[ 1 #3 - #3 gamma super 2 sub [xy] (f) #]", Position:In Text]  is a
  1718. measure of the mean square value of  [EQUATION "y(t)", Position:In Text]  not
  1719. accounted for by  [EQUATION "x(t)", Position:In Text]  at frequency
  1720. [EQUATION "f", Position:In Text] .  If  [EQUATION "x(t)", Position:In Text]
  1721. and  [EQUATION "y(t)", Position:In Text]  are completely unrelated, the
  1722. coherence function will be zero.  Furthermore, Bendat and Piersol (1986)
  1723. indicate that if the coherence function is greater than zero but less than
  1724. unity, one or more of the following three possible physical situations exist.
  1725.  
  1726.  
  1727.           1.   Extraneous noise is present in the measurements.
  1728.  
  1729.           2.   The system relating
  1730.                [EQUATION "x(t)", Position:In Text]  and
  1731.                [EQUATION "y(t)", Position:In Text]  is not linear.
  1732.  
  1733.           3.   [EQUATION "y(t)", Position:In Text]  is an output due
  1734.                to an input  [EQUATION "x(t)", Position:In Text]  as
  1735.                well as to other inputs.
  1736.  
  1737.  
  1738. The calculation of this function requires not only the computation of the cross
  1739. spectral density function but also the computation of power spectral densities
  1740. for each channel of data.  The code has been optimized to minimize the amount
  1741. of additional computational effort; however, in anticipation of the possibility
  1742. that a slow computer might be employed, the routine prompts the user for this
  1743. option at run-time.
  1744.  
  1745.      4.3.4 Error Estimates
  1746.  
  1747.      The definition of the coherence function makes possible at this point a
  1748. discussion of the error associated with estimates of the magnitude and phase of
  1749. the cross spectral density function and of the coherence function itself.  This
  1750. information comes from Bendat and Piersol (1986).  The normalized random error
  1751. of the estimate of the magnitude of the cross spectral density function is
  1752. given by
  1753.  
  1754.  
  1755. [EQUATION "center   | G sub [xy] (f) | #3 : #4#4 epsilon (f) #3#3 = #3#3 1 over
  1756.  
  1757.  
  1758.  
  1759. where  [EQUATION "| gamma sub [xy] (f) |", Position:In Text]  is the positive
  1760. square root of the coherence function evaluated at
  1761. [EQUATION "f", Position:In Text] , and  [EQUATION "n sub r", Position:In Text]
  1762. is the number of records in the input data file.  The error approaches that for
  1763. the power spectral density estimate (see equation 4.11) as
  1764. [EQUATION "| gamma sub [xy] (f) |", Position:In Text]  goes to one, and the
  1765. error is higher for values less than one.  Unlike the error estimate for the
  1766. power spectral density function, all of the error estimates in this section are
  1767. a function of frequency.
  1768.  
  1769.      Since the phase angle may assume the value zero, a normalized random error
  1770. cannot be specified; instead the standard deviation (s.d.) of the phase angle
  1771. estimate is given by
  1772.  
  1773.  
  1774. [EQUATION "center theta sub [xy] (f) #3 : #4#4 s. #3 d. #1 (f) #3#3 = #3#3 [ #[
  1775.  
  1776.  
  1777.  
  1778. The standard deviation is seen to approach zero as
  1779. [EQUATION "| gamma sub [xy] (f) |", Position:In Text]  goes to one and does so
  1780. independent of  [EQUATION "n sub r", Position:In Text]  for
  1781. [EQUATION "n sub r #3 > #3 1", Position:In Text] .  Continuing, the normalized
  1782. random error of the coherence function itself can also be calculated and is
  1783. defined as
  1784.  
  1785.  
  1786. [EQUATION "center gamma super 2 sub [xy] (f) #3 : #4#4 epsilon (f) #3#3 = #3#3
  1787. [
  1788.  
  1789.  
  1790.  
  1791. where the estimated value of the coherence function is substituted as an
  1792. approximation to the unknown true values of
  1793. [EQUATION "gamma super 2 sub [xy] (f)", Position:In Text]  and
  1794. [EQUATION "| gamma sub [xy] (f) |", Position:In Text]  called for in equation
  1795. 4.27.  Note that the normalized random error approaches zero as either
  1796. [EQUATION "n sub r #3 -> #3 infinity", Position:In Text]  or
  1797. [EQUATION "gamma super 2 sub [xy] #3 -> #3 1", Position:In Text] .  This
  1798. implies that coherence function estimates can be more accurate than either
  1799. autospectra or cross spectra estimates (which are used to calculate the
  1800. coherence function) when
  1801. [EQUATION "gamma super 2 sub [xy] (f)", Position:In Text]  is close to unity.
  1802. If the coherence function is calculated, the spectrum routine automatically
  1803. computes the three error estimates defined in equations 4.25 to 4.27 as a
  1804. function of frequency and saves the results in a separate output file.  The
  1805. file name and structure of this file will be discussed in the section on output
  1806. files.  Equations 4.25 to 4.27 are valid for the no taper and taper with
  1807. overlap cases.  If tapering is used without overlapping, then the error
  1808. estimates in equations 4.25 to 4.27 must each be increased by multiplying by
  1809. the square root of two, and this is automatically performed by the spectrum
  1810. routine.
  1811.  
  1812.      It is perhaps useful to know the number of records required in the input
  1813. data file to attain a specified normalized random error or standard deviation
  1814. for each of the estimates mentioned above.  This has been calculated for
  1815. various values of  [EQUATION "gamma super 2 sub [xy] (f)", Position:In Text]
  1816. for the cases:
  1817. [EQUATION "epsilon #3 #[ #3 | G sub [xy] (f) | #3 #] #3 = #3 0.1", Position:In
  1818. T
  1819.  ,
  1820. [EQUATION "epsilon #3 #[ #3 gamma super 2 sub [xy] (f) #3 #] #3 = #3 0.1",
  1821. Posit
  1822.   and
  1823. [EQUATION "s. #3 d. #3 #[ #3 theta sub [xy] (f) #3 #] #3 = #3 0.052 #3 rad #3
  1824. ~~
  1825.  , and the results are given in table 4.1 below.
  1826.  
  1827.  
  1828.  
  1829.         [EQUATION "gamma super 2 sub [xy] (f)", Position:In
  1830. Text]
  1831. 0.3    0.4    0.5    0.6    0.7    0.8    0.9
  1832.  
  1833.         [EQUATION "epsilon #3 #[ #3 | G sub [xy] (f) | #3 #] #3 = #3 0.1",
  1834. Position:In Text]
  1835. 334    250    200    167    143    125    112
  1836.  
  1837.         [EQUATION "s. #3 d. #3 #[ #3 theta sub [xy] (f) #3 #] #3 ~~ #3 3
  1838. degree",Position:In Text]
  1839. 426    274    183    122     79     46     21
  1840.  
  1841.         [EQUATION "epsilon #3 #[ #3 gamma super 2 sub [xy] (f) #3 #] #3 = #3
  1842. 0.1",Position:In Text]
  1843. 327    180    100     54     26     10     2
  1844.  
  1845.                 Table 4.1  Number of records for specified error
  1846.  
  1847. 4.4 Amplitude Spectral Density
  1848.  
  1849.      The amplitude spectrum option was added to allow the user to examine the
  1850. Fourier coefficients directly.  The amplitude spectrum is defined as
  1851.  
  1852.  
  1853. [EQUATION "center F sub x (f) #3#3 = #3#3 lim below [T -> infinity] #3#3 E #3
  1854. #[
  1855.  
  1856.  
  1857.  
  1858. where  [EQUATION "| X (f,T) |", Position:In Text]  is the modulus of the
  1859. quantity calculated in equation 4.6.  If the input data file contains two
  1860. channels of data, denoted as  [EQUATION "x(t)", Position:In Text]  and
  1861. [EQUATION "y(t)", Position:In Text] , then selection of this option results in
  1862. the computation of  [EQUATION "F sub x (f)", Position:In Text]  and
  1863. [EQUATION "F sub y (f)", Position:In Text] .
  1864.  
  1865.      A simple example taken from Stearns (1975) is used to demonstrate the
  1866. utility of this option.  Consider the following function which was
  1867. computer-generated and then saved as a set of digital values to simulate the
  1868. sampling process:
  1869.  
  1870.  
  1871. [EQUATION "center x(t) #3#3 = #3#3 e super [-t] #3 sin #3 t right #R(4.29)"]
  1872.  
  1873.  
  1874. A plot of a portion of this function is shown in figure 4.5.  The Fourier
  1875. transform of this function can be derived using the definition in equation 4.1
  1876. as
  1877.  
  1878.  
  1879. [EQUATION "center X(f) #3#3 = #3#3 1 over [[(i #3 2 pi f #3 + #3 1)] super [#3
  1880. 2
  1881.  
  1882.  
  1883.  
  1884. and the modulus of this quantity becomes
  1885.  
  1886.  
  1887. [EQUATION "center |X(f)| #3#3 = #3#3 1 over [ #[ #3 [(2 pi f)] super [#3 4] #3
  1888. +
  1889.  
  1890. [PAGE BREAK]
  1891.  
  1892.                   [WHITESPACE 0.25 in, Place All on Next Page]
  1893.  
  1894.                         [PICTURE FIG45.CGM, Scale:0.800]
  1895.  
  1896.                    Figure 4.5  Plot of example input function
  1897.  
  1898.                   [WHITESPACE 0.25 in, Place All on Next Page]
  1899.  
  1900.                         [PICTURE FIG46.CGM, Scale:0.800]
  1901.  
  1902.          Figure 4.6  Plot of amplitude spectrum calculation[PAGE BREAK]
  1903.  
  1904. This input function is deterministic, and therefore only one record of data
  1905. would normally be required; however, because an even number of records are
  1906. required by the spectrum routine for one channel of input data, two identical
  1907. records of this function were generated.
  1908. [EQUATION "N #3 = #3 2048", Position:In Text]  samples per record were created
  1909. with a time interval of  [EQUATION "Delta t #3 = #3 0.01", Position:In Text]
  1910. seconds between successive samples.  A portion of the results is shown in
  1911. figure 4.6 with the symbols representing the values computed by the spectrum
  1912. routine and the continuous line the values generated by equation 4.31.
  1913. [PAGE BREAK]
  1914.  
  1915.                     ^SU' Output Data Files
  1916.  
  1917.      For every input data file processed, the spectrum routine creates one (or
  1918. sometimes two) ASCII output files containing the results.  A second output file
  1919. is created only if the user processes two channels of input data and computes
  1920. the cross-spectral density and the coherence function; the second output file
  1921. then contains error estimates of cross-spectral magnitude and phase and of the
  1922. coherence function.
  1923.  
  1924. 5.1 Naming Convention
  1925.  
  1926.      The output file name will consist of nine characters.  The last four
  1927. characters specify the file extension; the default file extension, [.PRN], will
  1928. be used unless specified otherwise in the configuration file.  The first four
  1929. characters of the output file name will match the first four characters of the
  1930. corresponding input data file.  The fifth character is used to designate the
  1931. type of file that is being written.  The four possibilities are:
  1932.  
  1933.                      power spectrum                 P
  1934.  
  1935.                      cross spectrum                 C
  1936.  
  1937.                      amplitude spectrum             A
  1938.  
  1939.                      error estimates (if computed)  E
  1940.  
  1941. The output file will be written to the same location as the input data file;
  1942. this will, by default, be the location where the executable version of the
  1943. spectrum routine resides.  This location can be changed, however, in the
  1944. configuration file.
  1945.  
  1946. 5.2 File Structure
  1947.  
  1948.      These output data files consist of ASCII data as opposed to binary data.
  1949. They may be easily edited by any ASCII editor, imported into spreadsheet
  1950. programs for further manipulation or imported into plotting programs to be
  1951. graphed.  These files contain numbers only; no labels are included to describe
  1952. the various columns of data in the output.  While somewhat inconvenient for the
  1953. user, this was done to prevent the confusion that sometimes occurs when data
  1954. containing both numbers and labels are imported into other software programs.
  1955. In the sections that follow, a thorough description of the output to be
  1956. expected for each of the four types of output files is given, and this should
  1957. allow the user to interpret the results without any difficulty.
  1958.  
  1959.      5.2.1 Power Spectrum Output Files
  1960.  
  1961.      The first line of the output contains the mean and rms values computed as
  1962. described in equations 4.12 and 4.13 and then ensemble-averaged over all
  1963. records of the file.  Note that the mean and rms values reported here are
  1964. calculated subsequent to any cosmetic operations that may have been applied to
  1965. the data to improve the quality of the spectral density computation.  Removal
  1966. of the mean value, detrending, filtering and tapering operations may modify the
  1967. mean and rms so that they do not match the original values for the file which
  1968. were calculated and reported at run-time prior to the application of these
  1969. operations.  Continuing, the next line of the output file is blank.  The
  1970. calculated results begin on the third line and consist of four or six columns
  1971. of data depending on whether the input file contains one or two channels.  The
  1972. quantities are stored in the following order:
  1973.  
  1974.  
  1975.      One channel:
  1976.  
  1977. [EQUATION "center #^ #R[mean] #4#4 #R[rms] #4#4#4#4#4#4#4#4#4#4#4#4#4 end
  1978. center
  1979.  
  1980.  
  1981.  
  1982.      Two channels:
  1983.  
  1984. [EQUATION "center #^ #R[mean] #4#4 #R[rms] #4#4#4#4#4#4#4#4#4#4#4#4#4 end
  1985. center
  1986.  
  1987.  
  1988.  
  1989. In either case the output file contains
  1990. [EQUATION "N #1 / #1 2", Position:In Text]  rows of data after the blank line
  1991. with each row calculated for values of  [EQUATION "f", Position:In Text]
  1992. ranging from  [EQUATION "1 #1 / #1 N Delta t", Position:In Text]  to
  1993. [EQUATION "1 #1 / #1 2 Delta t", Position:In Text]  with a resolution of
  1994. [EQUATION "Delta f #3 = #3 1 #1 / #1 N Delta t", Position:In Text] .  This
  1995. structure is typical for all of the output files created by the spectrum
  1996. routine, and in the following descriptions of the output only the column labels
  1997. will be identified.
  1998.  
  1999.      5.2.2 Cross Spectrum Output Files
  2000.  
  2001.      A cross spectrum may only be calculated when the input file contains two
  2002. channels of data.  However, the output file is somewhat different depending
  2003. upon whether or not the coherence function is calculated.  In either case, the
  2004. file begins with the value of the cross correlation function evaluated at
  2005. [EQUATION "tau #3 = #3 0", Position:In Text]  and calculated according to
  2006. equation 4.18.  The next line is skipped, and the following record is the first
  2007. of  [EQUATION "N #1 / #1 2 ", Position:In Text]  rows of data arranged in five
  2008. or seven columns as described below.
  2009.  
  2010.  
  2011.      Coherence function not calculated:
  2012.  
  2013.  
  2014. [EQUATION "center #^ R sub [xy] (0) #4#4#4#4#4#4#4#4#4#4#4#4#4#4#4#4 end center
  2015.  
  2016.  
  2017.  
  2018.      Coherence function calculated:
  2019.  
  2020.  
  2021. [EQUATION "center #^ R sub [xy] (0) #4#4#4#4#4#4#4#4#4#4#4#4#4#4#4#4 end center
  2022.  
  2023.  
  2024.  
  2025.      5.2.3 Amplitude Spectrum Output Files
  2026.  
  2027.      When the amplitude spectrum option is chosen, the structure of the output
  2028. file is slightly different than for the other files.  No mean or rms value is
  2029. reported.  Instead, the file contains
  2030. [EQUATION "N #1 / #1 2 #3 + #3 1", Position:In Text]  rows of data arranged in
  2031. the columns shown below.  The first row consists of data computed for
  2032. [EQUATION "f #3 = #3 0", Position:In Text] ; data for this value of
  2033. [EQUATION "f", Position:In Text]  is not stored when other options are
  2034. selected, but is useful when examining the Fourier coefficients.  Actually, the
  2035. value  [EQUATION "f #3 = #3 epsilon", Position:In Text]  is used; this is
  2036. necessary since  [EQUATION "log #1 (0)", Position:In Text]  is undefined.  The
  2037. value of  [EQUATION "epsilon", Position:In Text] is defined in a PARAMETER
  2038. statement at the beginning of the code and is currently set at
  2039. [EQUATION "epsilon #3 = #3 1.0 #3 x #3 10 super [-20]", Position:In Text] .
  2040.  
  2041.  
  2042.      One channel:
  2043.  
  2044. [EQUATION "center matrix [[ [#^ f] [log #3 f] [F sub [x] (f)] #4#4#4#4#4#4 ] [
  2045. [
  2046.  
  2047. [PAGE BREAK]
  2048.  
  2049.      Two channels:
  2050.  
  2051. [EQUATION "center matrix [[ [#^ f] [log #3 f] [F sub [x] (f)] [F sub [y] (f)]
  2052. #4
  2053.  
  2054.  
  2055.  
  2056.      5.2.4 Error Estimate Output Files
  2057.  
  2058.      When both the cross-spectral density and the coherence function options
  2059. are selected, the spectrum routine calculates the errors associated with these
  2060. estimates as a function of frequency using equations 4.25 through 4.27.  These
  2061. error data are then stored in a separate file from the other results.  This
  2062. file contains  [EQUATION "N #1 / #1 2", Position:In Text]  rows of data
  2063. arranged in the columns identified below.  The columns containing normalized
  2064. random errors consist of dimensionless numbers, and the standard deviation of
  2065. the phase angle is expressed in degrees.
  2066.  
  2067.  
  2068. [EQUATION "center matrix [[ [#^ f] [log #3 f] [ epsilon #3 #[ #3 | G sub [xy]
  2069. (f
  2070.  
  2071.  
  2072.  
  2073.                  ^Sm" Run-time Considerations
  2074.  
  2075.      Two topics are discussed in this section which assume importance when the
  2076. program is executed.  The creation of a configuration file allows the user to
  2077. bend some of the rules regarding file name creation and the location of data
  2078. files as well as temporary files created by the spectrum routine.  The second
  2079. topic concerns the manner in which the size of the temporary files created by
  2080. the routine may be determined.
  2081.  
  2082. 6.1 Configuration File
  2083.  
  2084.      The presence of an ASCII file with the name SPECTRUM.CFG in the same
  2085. directory as the SPECTRUM.EXE file allows optional settings to take effect
  2086. which may have a favorable impact on the execution speed and overall ease of
  2087. use of the routine.  This ASCII file allows the user to specify three
  2088. parameters which will become default values when the program is executed.
  2089.  
  2090. 1.      The first item is the drive and path information for the location of
  2091.         input, output and coefficient data files.  If the user wishes to
  2092.         specify that these files may be found in (and written to) the same
  2093.         location as the SPECTRUM.EXE file, then the word ROOT should be entered
  2094.         on a line by itself.  Otherwise, the desired drive and path information
  2095.         should be entered in the following format:  C:\SPECTRUM\DATA\
  2096.         Note that the last backslash is required.
  2097.  
  2098. 2.      The second item in the file is the drive and path information which
  2099.         specifies where temporary data files created by the spectrum routine
  2100.         will be stored.  If a RAM disk is present on the user's computer and is
  2101.         large enough to hold the temporary files, then the execution speed of
  2102.         the routine will be greatly enhanced if these files are located on this
  2103.         RAM disk.  A means for estimating the size of these temporary files is
  2104.         discussed below.  Again, the user specifies ROOT or the desired drive
  2105.         and path information using a format such as:  D:\TEMP\
  2106.  
  2107. 3.      The last item allows the user to change the file extension for output
  2108.         data files from its default value of [.PRN] to some other desired
  2109.         value.  The user should place the extension on a line by itself in the
  2110.         following format:  .OUT
  2111.         Note that the leading period is required.
  2112.  
  2113. Comment lines may be included in the configuration file; these lines must start
  2114. with an asterisk character.  The routine is not case-sensitive -- the options
  2115. may be specified in upper or lower case.  The spectrum routine does not require
  2116. the presence of the configuration file; if this file is absent, then the
  2117. following default values are used:  1. root  2. root  3. [.prn]  If a
  2118. configuration file is used, then it must reside in the same directory as the
  2119. SPECTRUM.EXE file and all three options must be specified.  An example
  2120. configuration file follows.[PAGE BREAK]
  2121.  
  2122. *    This is a sample configuration file for Spectrum.  Comment lines
  2123. *    and blank lines must begin with an asterisk.
  2124. *
  2125. *    The first item in the file is the path where the input data
  2126. *    files are found and to which the output data will be written.
  2127. *    Acceptable values are: root, c:\ , g:\ , c:\test\bin\ , etc.  The
  2128. *    path must end with a backslash if root is not used.
  2129. root
  2130. *    The second item in the file is the drive on which the temporary
  2131. *    files are to be created.  Program execution speed will increase
  2132. *    dramatically if this is a RAM disk.
  2133. *    Acceptable values are: root, c:\ , g:\ , c:\test\bin\ , etc.  The
  2134. *    path must end with a backslash if root is not used.
  2135. d:\
  2136. *    The third item in the file is the default file extension to use
  2137. *    for the output data files.  If not specified in this file, then
  2138. *    the .PRN extension will be used in order that the data may be
  2139. *    imported into LOTUS for plotting.  The extension must consist of
  2140. *    a period followed by three letters.
  2141. .prn
  2142.  
  2143. 6.2 Temporary Files
  2144.  
  2145.      The input data files that are to be processed by the spectrum routine are
  2146. typically very large; therefore, the data is analyzed one record at a time.
  2147. Furthermore, the final result of the calculation is not arrived at in one pass;
  2148. instead, intermediate results are generated and stored in temporary files which
  2149. are then used to obtain the final results.  These temporary files are
  2150. automatically deleted upon completion; however, sufficient space must be
  2151. reserved on the hard disk or on a RAM disk for temporary use by these files.
  2152. The following discussion explains how these files are created and allows the
  2153. user to estimate their size based upon the size of the input data file.  Note
  2154. that if several input files are to be processed by the routine, only the
  2155. temporary files for the input data file currently being processed reside on the
  2156. hard disk at any one time; the user needs to allow sufficient space based upon
  2157. the size of the largest input data file.
  2158.  
  2159.      Two temporary files are created for each channel of input data.  After a
  2160. record of the input data file is read in by the routine, the integer data is
  2161. sorted into one or two arrays depending on the number of input channels; each
  2162. channel is then transformed into floating point data (if necessary), the mean
  2163. value or a linear trend is removed and any desired filtering takes place.
  2164. These data are then stored to temporary files with the extensions : [.TRF] -
  2165. channel 1 and [.TR2] - channel 2 (if required).  This process is repeated until
  2166. all records of the input data file are read.  If the input data file consisted
  2167. of 2-byte integers, then the [.TRF] file will be twice the size of the input
  2168. [.DAT] file since the [.TRF] file contains 4-byte floating point numbers.  If
  2169. the input data file consists of two channels of integer data, then the [.TRF]
  2170. and [.TR2] files will each be the same size as the [.DAT] file (the [.TRF] and
  2171. [.TR2] files each contain half as many numbers as the input [.DAT] file, but
  2172. each number is a 4-byte value).  If the input data file consists of one channel
  2173. of 4-byte real numbers, the [.TRF] file will be the same size as the [.DAT]
  2174. file, and finally, for two channels of 4-byte values in the input file, the
  2175. [.TRF] and [.TR2] files will each be half the size of the [.DAT] file.  After
  2176. creating the [.TRF] and [.TR2] (if required) files, the spectrum routine
  2177. proceeds to the tapering operation.  If tapering is selected, the routine reads
  2178. a record of data at a time from the [.TRF] and [.TR2] files, creates two new
  2179. records for each channel (if overlapping is used) and stores the results in two
  2180. temporary files with the extensions [.TAP] and [.TP2].  The last step in the
  2181. process is to transform the data stored in the [.TAP] and [.TP2] files and
  2182. perform the required spectral calculation.  The final data is written to one
  2183. output file regardless of the number of channels of input data and the
  2184. extension [.PRN], or alternatively an extension specified in the configuration
  2185. file is used.  If tapering is not selected, then the [.TAP] and [.TP2] files
  2186. are not created, and storage space does not need to be allocated. If the [.TAP]
  2187. and [.TP2] files are created, each will be twice the size of the previous
  2188. [.TRF] or [.TR2] file, since two tapered records are written for every input
  2189. record read to implement the 50% overlap technique.  (If tapering is employed
  2190. but overlapping is not, then the [.TAP] and [.TP2] files will be the same size
  2191. as the [.TRF] or [.TR2] file.  The table belows gives the worst case scenario
  2192. and assumes overlapping is used when tapering is used.)  At the end of the
  2193. calculation, only the original [.DAT] file and the final [.PRN] file will
  2194. remain.  If no alternative is specified in the configuration file, the
  2195. temporary files will be created in the same directory as the input data files.
  2196. Several examples follow which show the sizes of the various files based upon an
  2197. input data file size of 1 Mb.
  2198.  
  2199.  
  2200.  
  2201.  
  2202.       Two Channels ?      No        Yes         No        Yes         No
  2203.         Integers ?       Yes        Yes         No         No        Yes
  2204.         Tapering ?       Yes        Yes        Yes        Yes         No
  2205.  
  2206.           [.DAT]         1 Mb       1 Mb       1 Mb       1 Mb       1 Mb
  2207.           [.TRF]         2 Mb       1 Mb       1 Mb      500 kb      2 Mb
  2208.           [.TR2]          --        1 Mb        --       500 kb       --
  2209.           [.TAP]         4 Mb       2 Mb       2 Mb       1 Mb        --
  2210.           [.TP2]          --        2 Mb        --        1 Mb        --
  2211.           [.PRN]        64 kb      93 kb      48 kb      83 kb      64 kb
  2212.  
  2213.         Total Temp
  2214.        space needed      6 Mb       6 Mb       3 Mb       3 Mb       2 Mb
  2215.  
  2216.  
  2217.  
  2218.                  Table 4.2  Memory required for temporary files
  2219.  
  2220.                         ^So' Examples
  2221.  
  2222.      Three simple examples are considered that serve to illustrate various
  2223. features of the spectrum routine.  The example using colored noise demonstrates
  2224. the use of tapering and allows the calculated power spectrum to be compared
  2225. with a known power spectrum.  The computation of the amplitude spectrum of a
  2226. sinewave reveals the importance that sampling parameters can have on the
  2227. computed result, and the last example shows the effects of the application of a
  2228. variety of digital filters prior to the computation of power spectra.  A few
  2229. comments regarding the considerations necessary for the acquisition of
  2230. experimental data files are given at the end.
  2231.  
  2232. 7.1 Colored Noise
  2233.  
  2234.      A routine to produce bandwidth-limited white noise (colored noise) has
  2235. been written and used extensively during the testing phase of the development
  2236. of the spectrum routine.  This program prompts the user for a few parameters,
  2237. then generates the colored noise sequence and stores the output data in a
  2238. manner that simulates the sampling process.  This data may then be input into
  2239. the spectrum program, and the output power spectrum estimate may be compared
  2240. with the known power spectrum for colored noise.  This handy routine is a
  2241. useful utility program and has been included on the diskette with the name
  2242. COLOR.
  2243.  
  2244.      The procedure for producing colored noise begins by generating random
  2245. numbers that vary from 0 to 1.  This sequence is uniformly distributed over the
  2246. interval from 0 to 1.  Let  [EQUATION "x sub n", Position:In Text]  be the nth
  2247. random number, then  [EQUATION "x sub n #3 - #3 1 #1 / #1 2", Position:In Text]
  2248.   will be uniformly distributed over the interval from
  2249. [EQUATION "- 1 #1 / #1 2", Position:In Text]  to
  2250. [EQUATION "1 #1 / #1 2", Position:In Text] .  Now, recall that the mean and
  2251. variance of a uniformly distributed random variable is given by
  2252.  
  2253. [EQUATION "center mu sub x #3#3 = #3#3 [a #3 + #3 b] over 2 #4#4 #R[and] #4#4
  2254. si
  2255.  
  2256.  
  2257.  
  2258. where  [EQUATION "a", Position:In Text]  and  [EQUATION "b", Position:In Text]
  2259. are the endpoints of the interval.  Using these definitions, we find that the
  2260. mean and variance of the sequence
  2261. [EQUATION "x sub n #3 - #3 1 #1 / #1 2", Position:In Text]  is
  2262.  
  2263.  
  2264. [EQUATION "center mu sub x #3#3 = #3#3 0 #4#4 #R[and] #4#4 sigma sub x super 2
  2265. #
  2266.  
  2267.  
  2268.  
  2269. If a power spectrum for this sequence were calculated, then one would obtain
  2270. the mean value,  [EQUATION "mu sub x", Position:In Text] , the mean-square
  2271. value,  [EQUATION "psi sub x super 2", Position:In Text]  and the function
  2272. [EQUATION "G sub [xx] (f)", Position:In Text] .  Note that
  2273. [EQUATION "psi sub x super 2 #3 = #3 sigma sub x super 2 #3 + #3 mu sub x super
  2274.  , so that for this particular sequence
  2275.  
  2276.  
  2277. [EQUATION "center psi sub x super 2 #3#3 = #3#3 sigma sub x super 2 #3#3 = #3#3
  2278.  
  2279.  
  2280.  
  2281. If these data are considered to be samples of a continuous signal
  2282. [EQUATION "x(t)", Position:In Text]  with sampling interval
  2283. [EQUATION "Delta t", Position:In Text] , then the power spectrum should look
  2284. like that shown in figure 7.1.
  2285.  
  2286.  
  2287.                         [PICTURE FIG71.CGM, Scale:0.500]
  2288.  
  2289.                   Figure 7.1  White noise spectrum with total power P
  2290.  
  2291.  
  2292. For convenience, it is useful to adjust the total power in the sequence in
  2293. order that the power density
  2294. [EQUATION "G sub [xx] (f) #3 = #3 1", Position:In Text]  for
  2295. [EQUATION "0 #3 <= #3 f #3 <= #3 f sub c", Position:In Text]  where
  2296. [EQUATION "f sub c #3 = #3 1 #1 / #1 2 Delta t", Position:In Text]  is the
  2297. Nyquist frequency.  To accomplish this, consider the sequence
  2298.  
  2299. [EQUATION "center y sub n #3#3 = #3#3 K #3 (x sub n #3#3 - #3#3 1 over 2) right
  2300.  
  2301.  
  2302.  
  2303. where  [EQUATION "x sub n", Position:In Text]  is a random number on the
  2304. interval from 0 to 1 as before and  [EQUATION "y sub n", Position:In Text]
  2305. ranges from  [EQUATION "- K #1 / #1 2", Position:In Text]  to
  2306. [EQUATION "K #1 / #1 2", Position:In Text] .  For this sequence, the mean and
  2307. variance are
  2308.  
  2309.  
  2310. [EQUATION "center mu sub x #3#3 = #3#3 0 #4#4 #R[and] #4#4 sigma sub x super 2
  2311. #
  2312.  
  2313.  
  2314.  
  2315. Now, choose  [EQUATION "P #3 = #3 1 #1 / #1 2 Delta t", Position:In Text], so
  2316. that
  2317.  
  2318.  
  2319. [EQUATION "center psi sub x super 2 #3#3 = #3#3 sigma sub x super 2 #3#3 = #3#3
  2320.  
  2321.  
  2322.  
  2323. From this, we find that
  2324. [EQUATION "K #3 = #3 [(6 over [Delta t]) super [1/2]]", Position:In Text] , and
  2325. for this value of  [EQUATION "K", Position:In Text] , the power density for the
  2326. sequence defined in equation 7.4 satisfies
  2327.  
  2328.  
  2329. [EQUATION "center G sub [yy] (f) #3#3 = #3#3 #( { stack left [[ 1 #4#4 0 <= f
  2330. <=
  2331.  
  2332.  
  2333. A plot of this power spectrum is shown in figure 7.2.
  2334.  
  2335.  
  2336.                         [PICTURE FIG72.CGM, Scale:0.500]
  2337.  
  2338.                    Figure 7.2  White noise spectrum with total power
  2339.                [EQUATION "1 #1 / #1 2 Delta t", Position:In Text]
  2340.  
  2341.  
  2342. The final step is to create a new sequence
  2343. [EQUATION "z sub n", Position:In Text]  by passing the values
  2344. [EQUATION "y sub n", Position:In Text]  through a bandpass filter with transfer
  2345. function  [EQUATION "H(f)", Position:In Text] .  The power density for this new
  2346. sequence is given by
  2347.  
  2348.  
  2349. [EQUATION "center G sub [zz] (f) #3#3 = #3#3 | #1 H (f) #1 | super 2 #3#3 G sub
  2350.  
  2351.  
  2352.  
  2353. A recursive digital bandpass filter with
  2354. [EQUATION "| #1 H(f) #1 | #3 = #3 1", Position:In Text]  and described in
  2355. equation 3.15 has been used in the COLOR routine.  The user specifies the two
  2356. (-3 dB) points,  [EQUATION "f sub 1", Position:In Text]  and
  2357. [EQUATION "f sub 2", Position:In Text] , and the number of cascaded filter
  2358. stages to use.  The order of the filter is twice the number of cascaded
  2359. stages.  The output of the program is a sequence
  2360. [EQUATION "z sub n", Position:In Text]  with a power spectrum as shown in
  2361. figure 7.3.
  2362.  
  2363.  
  2364.                         [PICTURE FIG73.CGM, Scale:0.500]
  2365.  
  2366.                   Figure 7.3  Colored noise spectrum with total power
  2367.             [EQUATION "(f sub 2 #3 - #3 f sub 1)", Position:In Text]
  2368.  
  2369.  
  2370.      The color routine was used to create the sequence
  2371. [EQUATION "z sub n", Position:In Text]  (simulated sampling of the continuous
  2372. signal  [EQUATION "z(t)", Position:In Text] ) which was stored in a data file
  2373. that could be read by the spectrum routine.  The file contained 100 records
  2374. with 2048 data points per record.  The spacing between data points was 0.01
  2375. seconds.  The parameters for the bandpass filter were:
  2376. [EQUATION "f sub 1 #3 = #3 20 #3 Hz", Position:In Text] ,
  2377. [EQUATION "f sub 2 #3 = #3 30 #3 Hz", Position:In Text]  and five cascaded
  2378. stages for a tenth order filter.  A plot of a portion of the simulated time
  2379. series appears in figure 7.4.  The data file was processed by the spectrum
  2380. routine several times using various choices of tapering functions, and the
  2381. power spectra are plotted in figure 7.5.  When computing these spectra, no mean
  2382. removal or detrending was used, and no further filtering was performed.  As can
  2383. be seen,  [EQUATION "G sub [zz] (f) #3 = #3 1", Position:In Text]  in the
  2384. passband and rolls off to zero very rapidly elsewhere.  (Note that the base 10
  2385. logarithm of these numbers are plotted in order to magnify the rolloff
  2386. region.)  This plot clearly shows the advantages gained with the use of
  2387. tapering and overlapped processing as opposed to no tapering; however, in this
  2388. case, the choice of tapering function makes little difference.  Table 7.1 shows
  2389. the rms values reported for each case; all of these are within 0.6 % of the
  2390. theoretical value, and the minor variations are due to the fact that the
  2391. rolloff is not perfect.
  2392.  
  2393.  
  2394.                         [PICTURE FIG74.CGM, Scale:0.800]
  2395.  
  2396.           Figure 7.4  Simulated time series  [EQUATION "z(t)", Position:In
  2397. Text]
  2398.  
  2399.  
  2400.  
  2401.  
  2402.                    Theory    No Taper   Hanning     Parzen     Tukey      Welch
  2403.  
  2404.    rms values     3.16228    3.14463    3.14665    3.14617    3.14315
  2405. 3.14429
  2406.  
  2407.     error (%)        --        0.56       0.49       0.51       0.60       0.57
  2408.  
  2409.  
  2410.  
  2411.                Table 7.1  RMS values reported by spectrum routine
  2412.  
  2413.             [PAGE BREAK][WHITESPACE 0.25 in, Place All on Next Page]
  2414.  
  2415.                         [PICTURE FIG75.CGM, Scale:0.800]
  2416.  
  2417.                Figure 7.5  Power spectra for colored noise; total power =
  2418.                     [EQUATION "root[10]", Position:In Text]
  2419.  
  2420.  
  2421.  
  2422.                         [PICTURE FIG76.CGM, Scale:0.800]
  2423.  
  2424.                 Figure 7.6  Effect of detrend on power spectra[PAGE BREAK]
  2425.  
  2426. For data generated by the computer, no linear trend in the data is to be
  2427. expected, and the detrending operation should not be used.  The indiscriminate
  2428. use of this operation can lead to added power at
  2429. [EQUATION "f #3 = #3 1 #1 / #1 N Delta t", Position:In Text]  since this
  2430. operation is applied record by record; this can only occur if the power at this
  2431. frequency is lower than the small amount of noise generated by the use of this
  2432. operation.  In almost every case where the random data originates from an
  2433. experiment (vis-a-vis computer generated perfect random data) this problem will
  2434. not occur, but the user should be aware of the possibility.  A plot of the
  2435. added power that occurs with the use of the detrending operation is shown in
  2436. figure 7.6.
  2437.  
  2438.      The following is an example session showing the various prompts and
  2439. responses that were used with the color routine for this example.
  2440.  
  2441.  
  2442. color
  2443.  
  2444. Enter the low frequency cutoff : 20.0
  2445.                                                       (Defines passband)
  2446. Enter the high frequency cutoff : 30.0
  2447.  
  2448. Enter delta T seconds. (1.0/Sample Rate) : 0.01       (Sampling rate = 100 Hz)
  2449.  
  2450. Enter # of filter sections to cascade : 5             (Tenth order filter)
  2451.  
  2452. Enter # of points per record (N) : 2048               (Must be power of two)
  2453.  
  2454. Enter # of records (NUMREC) : 100                     (No limit on # records)
  2455.  
  2456. Enter a negative integer : -5                          (Required seed value
  2457. for)
  2458.                                                       (random number generator)
  2459. Enter output file name (4 chars) : COLR
  2460.  
  2461.               C O L O R E D   N O I S E   U T I L I T Y
  2462.  
  2463.                         Creating COLR.DAT now.
  2464.  
  2465.                         Writing record 0100
  2466.  
  2467.               Use voltage transformation factor = 20.0 / 4096.0
  2468.  
  2469.                    Program terminated successfully.
  2470.  
  2471.  
  2472.      Next is an example session showing the prompts and responses needed to
  2473. process the COLR.DAT file using the spectrum routine.
  2474.  
  2475.  
  2476. spectrum colr
  2477.  
  2478. Transform into (V)oltages or into (O)ther quantity
  2479. or read (R)eal data which is already transformed : v
  2480.  
  2481. Enter VOFST 1) 10/4096, 2) 20/4096, 3) 2/4096 or 4) other : 2
  2482.  
  2483. Remove (M)ean value, (D)etrend or (N)either : n
  2484.  
  2485. Filter the data using (L)owpass, (H)ighpass
  2486.                    (B)andpass, Band(S)top or (N)one : n
  2487.  
  2488. How many channels of data (1 or 2) : 1
  2489.  
  2490. (A)mplitude, (P)ower or (C)ross spectrum : p
  2491.  
  2492. Taper the data (Y/N) : y
  2493.  
  2494. (H)anning, (P)arzen, (T)ukey or (W)elch window : h
  2495.  
  2496. Use overlap (Y/N) : y
  2497.  
  2498.                         Processing COLR.DAT now.
  2499.  
  2500.                Record 0100  Ave = .15974E-03   Rms = 3.1035
  2501.  
  2502.                File Totals : Ave = .26703E-05  Rms = 3.1446
  2503.  
  2504.                         Taper applied = Hanning.
  2505.                         50% overlap used.
  2506.                         0200 records will be written.
  2507.  
  2508.                         Tapering record 0200.
  2509.  
  2510.                         Transforming records 0199 and 0200.
  2511.  
  2512.                         Record 0200 was discarded.
  2513.  
  2514.                         Writing COLRP.PRN now.
  2515.  
  2516.                              mean         rms
  2517.                          2.18332E-06     3.1467
  2518.  
  2519.                         norm. random error = .10000
  2520.  
  2521.                         starting time :  09:15:01.71
  2522.                         ending time   :  09:16:06.68
  2523.                         elapsed time  :  00:01:04.97
  2524.  
  2525.                         Program terminated successfully.
  2526.  
  2527.  
  2528.      Note that the maximum number of points per record is controlled by the
  2529. value of NMAX.  The value of NMAX is currently set to 16384.  (If the user
  2530. should ever desire to make a change to the value of NMAX, the change must be
  2531. made both in the COLOR routine and also in the SPECTRUM routine.  NMAX must be
  2532. the same number in both routines at all times.)
  2533.  
  2534. 7.2 Sinusoidal Input
  2535.  
  2536.      When developing the spectrum routine, it was felt that a simple test would
  2537. be to attempt to determine the Fourier coefficient (amplitude) of a sinewave by
  2538. computing its amplitude spectrum.  Although this can be done, it is not a
  2539. trivial procedure and is therefore repeated here as an example.  A sinewave
  2540. generation routine was written and is included on the diskette as SINE; this
  2541. routine creates a data file that can be read by the spectrum routine.  Each
  2542. record of this data file contains a portion of the time series
  2543.  
  2544.  
  2545. [EQUATION "center x(t,k) #3#3 = #3#3 A #3 sin #3 #[ 2 pi f sub 0 #1 t #3#3 +
  2546. #3#
  2547.  
  2548.  
  2549.  
  2550. where  [EQUATION "A", Position:In Text]  is the amplitude,
  2551. [EQUATION "f sub 0", Position:In Text]  is the frequency and
  2552. [EQUATION "theta sub k", Position:In Text]  is a phase angle which changes from
  2553. record to record and is a function therefore of the record number
  2554. [EQUATION "k", Position:In Text] .  The presence of a changing phase angle from
  2555. record to record is merely to simulate sampling of noncontiguous chunks of the
  2556. continuous function.  This phase angle will not alter the value of the
  2557. amplitude spectrum and is therefore left out of the following derivation for
  2558. simplicity.
  2559.  
  2560.      The finite-range Fourier transform defined in equation 4.2 can be computed
  2561. for this function  [EQUATION "x(t)", Position:In Text]  and is given by
  2562.  
  2563.  
  2564. [EQUATION "center X(f,T) #3#3 = #3#3 [AT] over [2i] #3#3 [#[ #3 [sin #3 pi #3
  2565. (f
  2566.  
  2567.  
  2568.  
  2569. This function must now be evaluated at
  2570. [EQUATION "f #3 = #3 f sub 0", Position:In Text] , so taking the limit gives
  2571.  
  2572.  
  2573. [EQUATION "center lim below [f -> f sub 0] #3#3 X(f,T) #3#3 = #3#3 [AT] over
  2574. [2i
  2575.  
  2576.  
  2577.  
  2578. where the first term was evaluated using l'Hôpital's rule.  The modulus of this
  2579. quantity is a function of the record length  [EQUATION "T", Position:In Text] ,
  2580. and is given by
  2581.  
  2582.  
  2583. [EQUATION "center | #3 lim below [f -> f sub 0] #3#3 X(f,T) #3 | #3#3 = #3#3
  2584. [AT
  2585.  
  2586.  
  2587.  
  2588. To further examine this dependence upon the record length, one can express
  2589. [EQUATION "T", Position:In Text]  in terms of  [EQUATION "n", Position:In Text]
  2590.  , the number of cycles of the sinewave, using
  2591.  
  2592.  
  2593. [EQUATION "center T #3#3 = #3#3 N Delta t #3#3 = #3#3 n over [f sub 0] right
  2594. #R(
  2595.  
  2596.  
  2597.  
  2598. With this value for the record length, equation 7.12 becomes
  2599.  
  2600.  
  2601. [EQUATION "center | #3 lim below [f -> f sub 0] #3#3 X(f,T) #3 | #3#3 = #3#3
  2602. [AT
  2603.  
  2604.  
  2605.  
  2606. The function  [EQUATION "f #1 (#1 n)", Position:In Text]  is plotted in figure
  2607. 7.7 and is shown to oscillate about the value one.  The extent of the
  2608. oscillation decreases with increasing  [EQUATION "n", Position:In Text] , and
  2609. in the limit as the record length goes to infinity, the function equals one.
  2610.  
  2611.  
  2612.                         [PICTURE FIG77.CGM, Scale:0.800]
  2613.  
  2614.                             Figure 7.7  Oscillatory function
  2615.                    [EQUATION "f #1 (#1 n)", Position:In Text]
  2616.  
  2617.  
  2618. Due to the finite nature of the signal, one can obtain the limiting value for
  2619. the Fourier coefficient only by paying careful attention to the choice of
  2620. record length.  Specifically, if the record length is chosen to contain an
  2621. integral number of cycles of the sinewave, then as can be seen from
  2622. figure 7.7,  [EQUATION "f #1 (#1 n) #3 = #3 1", Position:In Text]  for integer
  2623. [EQUATION "n", Position:In Text] .  Summarizing then, the limiting value of the
  2624. amplitude spectrum of the sinewave can be computed if the record length is
  2625. chosen to contain an integral number of cycles of the sinewave; when this
  2626. criterion is satisfied, then the modulus is given by
  2627.  
  2628.  
  2629. [EQUATION "center | #3 lim below [f -> f sub 0] #3#3 X(f,T) #3 | #3#3 = #3#3
  2630. [AT
  2631.  
  2632.  
  2633.  
  2634. Now, using the definition given in equation 4.28, the value of the amplitude
  2635. spectrum reported by the spectrum routine at the frequency
  2636. [EQUATION "f sub 0", Position:In Text]  will be the ensemble average over all
  2637. records of the data file of the modulus defined in equation 7.15.  Three
  2638. further constraints are placed upon the record length in addition to the
  2639. requirement of integral values of  [EQUATION "n", Position:In Text] :
  2640. [EQUATION "N", Position:In Text] must be a power of two,
  2641. [EQUATION "N", Position:In Text]  should be large for better accuracy and
  2642. [EQUATION "Delta t #3 <= #3 1 #1 / #1 [2 f sub 0]", Position:In Text]  which is
  2643. a statement of the fact that the frequency of the sinewave must be less than or
  2644. equal to the Nyquist frequency determined by the sampling interval.  These
  2645. requirements are satisfied if
  2646. [EQUATION "Delta t #3 = #3 1 #1 / #1 [2 super j #1 f sub 0]", Position:In Text]
  2647.  ,  [EQUATION "N #3 = #3 2 super k", Position:In Text]  and
  2648. [EQUATION "k >> j", Position:In Text]  for integer values of
  2649. [EQUATION "j", Position:In Text]  and  [EQUATION "k", Position:In Text] ; for
  2650. these choices  [EQUATION "n #3 = #3 2 super [#3 k-j]", Position:In Text] .
  2651. Generally, the best accuracy is obtained when
  2652. [EQUATION "n #3 = #3 N #1 / #1 4", Position:In Text]  (
  2653. [EQUATION "j #3 = #3 2", Position:In Text] ).
  2654.  
  2655.      As an example of this technique, the sinewave
  2656.  
  2657.  
  2658. [EQUATION "center x(t,k) #3#3 = #3#3 1.25 #3#3 sin #3#3 #[ 2 pi #3 (128.0) #3 t
  2659.  
  2660.  
  2661.  
  2662. was created using the SINE routine.  The file contained ten records with 8192
  2663. points per record.  The sampling interval was chosen to be (using
  2664. [EQUATION "n #3 = #3 N #1 / #1 4", Position:In Text] )
  2665.  
  2666.  
  2667. [EQUATION "center Delta t #3#3 = #3#3 1 over [(4)(128)] #3#3 = #3#3 0.001953125
  2668.  
  2669.  
  2670.  
  2671. so that the record contained exactly 2048 cycles of the sinewave.  The spectrum
  2672. should have a peak at a frequency of 128 Hz where the amplitude is given by
  2673.  
  2674.  
  2675. [EQUATION "center F sub x (128) #3#3 = #3#3 lim below [T -> infinity] #3#3 E #3
  2676.  
  2677.  
  2678.  
  2679. The actual value reported by the spectrum routine was 9.9656 at a frequency of
  2680. 128.0082 Hz which was the closest discrete frequency value.  A plot of the
  2681. amplitude spectrum is shown in figure 7.8.  When computing this spectrum, no
  2682. mean removal or detrending was used, and no filtering was performed.
  2683. Furthermore, application of a tapering function would significantly change the
  2684. expected amplitude spectrum and therefore no tapering was used.
  2685.  
  2686.  
  2687.                         [PICTURE FIG78.CGM, Scale:0.800]
  2688.  
  2689.                         Figure 7.8  Amplitude spectrum of sinewave
  2690.  
  2691.  
  2692. The required inputs to the SINE routine follow.
  2693.  
  2694.  
  2695. sine
  2696.  
  2697. Enter the amplitude of the sinewave : 1.25            (gives a simple answer)
  2698.  
  2699. Enter the frequency of the sinewave : 128.0           (can be any desired
  2700. number)
  2701.  
  2702. Enter the phase (in degrees) : 32.8                   (choose any initial
  2703. value)
  2704.  
  2705. Enter DC value : 0.0                                   (no DC for this example)
  2706.  
  2707. Enter delta T secs. (1.0/Sample Rate) : 0.001953125   (according to eq. 7.17)
  2708.  
  2709. Enter # of points per record (N) : 8192               (must be power of 2)
  2710.  
  2711. Enter # of records (ASIZE) : 10                       (OK for this example)
  2712.  
  2713. Enter output file name (4 chars) : SINE
  2714.  
  2715.               S I N E W A V E   C R E A T I O N   U T I L I T Y
  2716.  
  2717.                         Creating SINE.DAT now.
  2718.  
  2719.                         Writing record 0010
  2720.  
  2721.               Use voltage transformation factor = 20.0 / 4096.0
  2722.  
  2723.                    Program terminated successfully.
  2724.  
  2725.  
  2726. The required inputs to the spectrum routine to create the amplitude spectrum
  2727. given in figure 7.8 follow.
  2728.  
  2729.  
  2730. spectrum sine
  2731.  
  2732. Transform into (V)oltages or into (O)ther quantity
  2733. or read (R)eal data which is already transformed : v
  2734.  
  2735. Enter VOFST 1) 10/4096, 2) 20/4096, 3) 2/4096 or 4) other : 2
  2736.  
  2737. Remove (M)ean value, (D)etrend or (N)either : n
  2738.  
  2739. Filter the data using (L)owpass, (H)ighpass
  2740.                    (B)andpass, Band(S)top or (N)one : n
  2741.  
  2742. How many channels of data (1 or 2) : 1
  2743.  
  2744. (A)mplitude, (P)ower or (C)ross spectrum : a
  2745.  
  2746. Taper the data (Y/N) : n
  2747.  
  2748.                         Processing SINE.DAT now.
  2749.  
  2750.                    Record 0010 : Ave = .00000  Rms = .88208
  2751.  
  2752.                    File Totals   : Ave = .00000  Rms = .88090
  2753.  
  2754.                         No tapering applied.
  2755.                         0010 records will be used.
  2756.  
  2757.                         Transforming records 0009 and 0010.
  2758.  
  2759.                         Writing SINEA.PRN now.
  2760.  
  2761.                         starting time :  20:24:53.77
  2762.                         ending time   :  20:25:13.21
  2763.                         elapsed time  :  00:00:19.44
  2764.  
  2765.                         Program terminated successfully.
  2766.  
  2767.  
  2768.      Note that the maximum number of points per record is controlled by the
  2769. value of NMAX.  The value of NMAX is currently set to 16384.  (If the user
  2770. should ever desire to make a change to the value of NMAX, the change must be
  2771. made both in the SINE routine and also in the SPECTRUM routine.  NMAX must be
  2772. the same number in both routines at all times.)[PAGE BREAK]
  2773.  
  2774. 7.3 Experimental Noise Input
  2775.  
  2776.      The input data file for this example was derived from an experiment
  2777. employing an electrodynamic shaker table.  This device is essentially a large
  2778. solenoid mated to an electronic feedback system which is used to accurately
  2779. control the oscillatory motion of the core.  The displacement amplitude and
  2780. frequency can be set to desired levels and then maintained very accurately.
  2781. This instrument was used in an experiment designed to test the frequency
  2782. response of an optical system which was built to measure displacement of a
  2783. surface at a point.  Prior to the actual frequency response test, the optical
  2784. system was used to measure the displacement of the core of the solenoid with
  2785. the shaker table energized but undergoing no motion.  The computation of a
  2786. power spectrum of this displacement noise can then be a useful diagnostic tool
  2787. for the identification of noise sources in subsequent displacement spectrum
  2788. measurements.
  2789.  
  2790.      The signal was digitized using a 12-bit A/D converter with an input range
  2791. of -10 to 10 V.  The sampling rate was 2 kHz which resulted in a sampling
  2792. interval of  [EQUATION "Delta t #3 = #3 0.0005", Position:In Text]  seconds.
  2793. 80 records of data were acquired with 2048 points per record.  The power
  2794. spectrum was computed for a range of frequencies up to the Nyquist frequency
  2795. which was 1 kHz; the resolution was given by
  2796. [EQUATION "Delta f #3 = #3 1 #1 / #1 N Delta t #3 = #3 0.97656 #3 Hz",
  2797. Position:
  2798.  .  All power spectra shown in this section were computed by first detrending,
  2799. then tapering the input time records with the Welch taper and employing 50%
  2800. overlap.  The resulting power spectrum is shown in figure 7.9; logarithmic
  2801. scales are used for greater clarity.  The figure reveals that most of the power
  2802. in the signal lies below 100 Hz.  A 60 Hz contribution attributable to the
  2803. power supply may be identified as well as other resonances and their harmonics.
  2804.  
  2805.  
  2806.                         [PICTURE FIG79.CGM, Scale:0.800]
  2807.  
  2808.                       Figure 7.9  Power spectrum of displacement noise
  2809.  
  2810.  
  2811.      This input file allows a useful demonstration of the filtering
  2812. capabilities of the spectrum routine.  Shown in Figure 7.10 are power spectra
  2813. of the same input file for which figure 7.9 was obtained; however, prior to the
  2814. spectral calculation, each of the four types of filters available for use were
  2815. applied to the data.  In each case five cascaded filter stages were used
  2816. providing a tenth order digital Butterworth filter.  As can be seen, the
  2817. rolloff is extremely rapid with power in the stopband 3 to 4 decades below that
  2818. in the passband.  This is an effective means for removing undesirable frequency
  2819. components from the data prior to spectral computation.  This can also be
  2820. useful for quickly estimating the amount of power contributed by specific peaks
  2821. or regions of the spectrum.  The rms value, calculated as the square root of
  2822. the area under the spectral density curve (according to eq. 4.13), is given in
  2823. table 7.2 for each of the filter cases shown in figure 7.10 and for the
  2824. no-filter case plotted in figure 7.9.
  2825.  
  2826.  
  2827.  
  2828.                     No filter   Lowpass    Highpass   Bandpass   Bandstop
  2829.  
  2830.       rms values     0.014803   0.013319   0.009529   0.005894   0.010116
  2831.  
  2832.  
  2833.  
  2834.       Table 7.2  RMS values reported after application of each filter type
  2835.  
  2836.  
  2837. The table indicates that about 10% of the contribution to the root-mean-square
  2838. value of the signal may be found above 100 Hz, about a third lies below 30 Hz
  2839. and just under half may be found between 50 and 100 Hz.  However, adding the
  2840. rms value for the bandpass case to the rms value for the bandstop case does not
  2841. equal the rms value for the no filter case.  This discrepancy is due to the
  2842. fact that some power is in the stopband for the bandpass and bandstop cases,
  2843. and this contributes a small amount to the rms values indicated.  Therefore,
  2844. this method should only be used for rough estimates; the most accurate method
  2845. is to integrate the spectral density function over frequency bands of interest.
  2846. [PAGE BREAK]
  2847.  
  2848.                    [WHITESPACE 4 in, Place All on Next Page]
  2849.  
  2850.                Substitute Figure 7.10 for this page.[PAGE BREAK]
  2851.  
  2852. 7.4 Sampling Considerations
  2853.  
  2854.      A full discussion of sampling procedures will not be reiterated here; a
  2855. complete discussion of these techniques can be found in the references, and the
  2856. interested reader is urged to look there.  Instead, this section attempts to
  2857. present some of the considerations necessary when making choices among the
  2858. various sampling parameters, and the manner in which these choices affect the
  2859. spectral density results.
  2860.  
  2861.      The most important parameter is probably the choice of sampling interval
  2862. [EQUATION "Delta t", Position:In Text] .  In general, one attempts to choose
  2863. this quantity to be of the order of the smallest time scale of interest in the
  2864. physical phenomenon under investigation.  The selection of
  2865. [EQUATION "Delta t", Position:In Text]  determines the largest frequency
  2866. (bandwidth) of the resulting spectral analysis.  This critical frequency
  2867. [EQUATION "f sub c", Position:In Text]  is known as the Nyquist frequency and
  2868. is given by
  2869.  
  2870.  
  2871. [EQUATION "center f sub c #3#3 = #3#3 1 over [2 Delta t] right #R(7.19)"]
  2872.  
  2873.  
  2874. Another quick way for determining the Nyquist frequency is to note that
  2875. [EQUATION "f sub c #3 = #3 f sub s #1 / #1 2", Position:In Text]  where
  2876. [EQUATION "f sub s #3 = #3 1 #1 / #1 Delta t", Position:In Text]  is the
  2877. sampling rate at which data are acquired.  If energy exists in the signal above
  2878. the Nyquist frequency determined by the desired sampling rate, then this energy
  2879. must be removed by means of an analog lowpass filter prior to A/D conversion.
  2880. This is necessary to prevent aliasing of the high frequency components in the
  2881. data.  Aliasing is essentially confusion among the high and low frequency
  2882. components in the data that occurs whenever the sampling rate is set too low.
  2883. A very good discussion of aliasing may be found in Bendat and Piersol (1986).
  2884.  
  2885.      Another parameter of interest is the number of data points per record per
  2886. channel  [EQUATION "N", Position:In Text] .  This quantity combined with the
  2887. choice of  [EQUATION "Delta t", Position:In Text]  determines the record
  2888. length  [EQUATION "T #3 = #3 N Delta t", Position:In Text]  and the resolution
  2889. bandwidth of the spectral analysis,
  2890.  
  2891.  
  2892. [EQUATION "center Delta f #3#3 = #3#3 1 over [N Delta t] right #R(7.20)"]
  2893.  
  2894.  
  2895. A large value of  [EQUATION "N", Position:In Text]  for a given value of
  2896. [EQUATION "Delta t", Position:In Text]  gives a smaller
  2897. [EQUATION "Delta f", Position:In Text]  and can give a more detailed spectral
  2898. density estimate.  On the other hand, if the record length
  2899. [EQUATION "T", Position:In Text]  is very long, realizability problems may
  2900. occur: is the physical phenomenon stationary for these long time periods?  Is
  2901. there a limitation on maximum file size?  Can the resulting massive amounts of
  2902. data be adequately stored?
  2903.  
  2904.      Another important parameter is the number of records
  2905. [EQUATION "n sub r", Position:In Text]  of length
  2906. [EQUATION "T", Position:In Text]  to sample for each data file.  These records
  2907. should be contiguous in time (in order to use overlapping) and constitute an
  2908. ensemble of statistically stationary records; the expected value operation
  2909. contained in the definitions of the spectral density estimates is approximated
  2910. when an ensemble average is calculated for this set.  Recall, that it is
  2911. [EQUATION "n sub r", Position:In Text]  (the number of records before
  2912. overlapping) which is used in the determination of the errors associated with
  2913. each of the spectral density estimates and not  [EQUATION "N", Position:In
  2914. Text]
  2915.   or  [EQUATION "Delta t", Position:In Text] .  Increasing
  2916. [EQUATION "n sub r", Position:In Text]  rapidly decreases the normalized random
  2917. error  [EQUATION "epsilon", Position:In Text]  up to about
  2918. [EQUATION "n sub r #3 = #3 100", Position:In Text]  or so; for larger values
  2919. of  [EQUATION "n sub r", Position:In Text]  the error decreases much more
  2920. slowly.  There may be certain situations in which, for a given overall file
  2921. size, it is better to increase  [EQUATION "n sub r", Position:In Text]  and
  2922. decrease  [EQUATION "N", Position:In Text]  for a given
  2923. [EQUATION "Delta t", Position:In Text]  in order to increase accuracy at the
  2924. expense of resolution bandwidth  [EQUATION "Delta f", Position:In Text] .
  2925.  
  2926.                     ^S▒" Utility Routines
  2927.  
  2928.      Four utility programs are included on the diskette.  The SINE and COLOR
  2929. routines have been discussed in the previous section concerning examples.
  2930. MAKDAT is a routine designed to read a data file in ASCII format and then to
  2931. write the necessary file header and data to an unformatted file.  MAKCOEF is
  2932. similar; it reads a user-prepared ASCII format coefficient data file and then
  2933. writes the file header and coefficients to an unformatted file.  It is easiest,
  2934. of course, to add the necessary code to create the unformatted files directly
  2935. to the routine that is used to create (or collect) the data in the first place;
  2936. however, if the user is unfamiliar with unformatted FORTRAN data files or the
  2937. FORTRAN language in general, then these routines attempt to solve the problem.
  2938.  
  2939. 8.1 MAKDAT routine
  2940.  
  2941.      In order to use MAKDAT, the data to be analyzed by the spectrum routine
  2942. must be generated, or collected by an A/D converter, and then stored to a file
  2943. in ASCII format.  In this format the file may be viewed by any ASCII editor,
  2944. can be displayed on the screen and can be printed on a printer.  This is not an
  2945. optimum way to store data; these files tend to be extremely large.  In
  2946. anticipation of this fact other types of data files were explored for possible
  2947. use, and unformatted FORTRAN files appeared to be the simplest solution.
  2948. Unformatted files are typically a factor of five smaller in size than the
  2949. equivalent ASCII file.  An example will be given to illustrate the means for
  2950. transferring the data to unformatted files which can then be used by SPECTRUM.
  2951.  
  2952.      Suppose that 100 records of one channel of data saved as 2-byte integers
  2953. and sampled at 10000 samples per second with 2048 data points per record have
  2954. been acquired.  These data should be placed in an ASCII file with the file
  2955. extension [.ASC] and with a file name conforming to the various naming
  2956. conventions discussed earlier.  The file must contain numbers only; the numbers
  2957. may be written one per line or many per line (but this does not shorten the
  2958. length of the file).  Blank lines may be added if desired.  The first number in
  2959. the file should be the first data point of the first record; the 2049th number
  2960. in the file should be the first data point of the second record, and the last
  2961. number in the file should be the 2048th data point of the 100th record.  A
  2962. session with MAKDAT to accomplish this transformation would proceed as follows.
  2963.  
  2964.  
  2965. makdat
  2966.  
  2967. (I)nteger (2-byte) or (F)loating-point (4-byte) data : i
  2968.  
  2969. Enter # of channels (1 or 2) : 1
  2970.  
  2971. One channel  : Total # points per record <= 16384.
  2972. Two channels : Total # points per record per channel <= 8192.
  2973.  
  2974. Enter # of points per record (power of two) : 2048
  2975.  
  2976. One channel  : Must be EVEN # of records.
  2977. Two channels : May be EVEN or ODD # of records.
  2978.  
  2979. Enter # of records in the data file : 100
  2980.  
  2981. One chan    : Delta t is spacing between data points.
  2982. Two chans : Delta t is spacing between data pts - SAME channel
  2983.               Delta t divided by 2 is spacing between data pts
  2984.               - different channels.
  2985.  
  2986. Enter sampling interval delta t (secs) : 0.0001
  2987.  
  2988. Enter ASCII input file name (4 chars) : test
  2989.  
  2990.               D A T A   F I L E   C R E A T I O N   U T I L I T Y
  2991.  
  2992.                        Creating TEST.DAT now.
  2993.  
  2994.                        # channels = 1
  2995.                        record size = 4096 bytes
  2996.                        # of records = 100
  2997.                        delta t = 100 microseconds
  2998.  
  2999.                        Record 0100
  3000.  
  3001.                        Program terminated successfully.
  3002.  
  3003.  
  3004. The MAKDAT routine reads the user-prepared TEST.ASC file and calculates the
  3005. values needed for the file header.  The file header would consist of
  3006.  
  3007.  
  3008. [EQUATION "center 1 #4#4 4096 #4#4 100 #4#4 100 #4#4"]
  3009.  
  3010.  
  3011. The routine then transfers the data to the unformatted file with the name
  3012. TEST.DAT.  Finally, to process this file with the spectrum routine the user
  3013. would enter: spectrum test.
  3014.  
  3015.      For two channels of data, it is necessary that the numbers be stored in
  3016. each record of the ASCII file in the following manner:
  3017.  
  3018.  
  3019. [EQUATION "center #R[one] #4 #R[channel] #^ #R[:] #4#4 x sub 0 #3 x sub 1 #3 x
  3020. s
  3021.  
  3022.  
  3023.  
  3024. using the notation defined earlier.  Therefore, the first number in the file
  3025. will be the first data point of the first record for channel 1; the second
  3026. number will be the first data point of the first record for channel 2; the
  3027. third number in the file will be the second number for the first record of
  3028. channel 1, and so on.  Also, care should be taken to enter correct responses to
  3029. the prompts when two channels of data are to be transferred.  In response to
  3030. the number of points per record per channel prompt, the user would enter 1024
  3031. points if the data file consisted of two channels of data with 2048 points per
  3032. record and therefore 1024 points for each channel in each record.  Note that
  3033. the maximum number of points per record is controlled by the value of NMAX; the
  3034. maximum number of points per record per channel is then NMAX / 2.  The value of
  3035. NMAX is currently set to 16384.  (If the user should ever desire to make a
  3036. change to the value of NMAX, the change must be made both in the MAKDAT routine
  3037. and also in the SPECTRUM routine.  NMAX must be the same number in both
  3038. routines at all times.)  Similarly, when responding to the prompt for the
  3039. sampling interval, the user would enter 0.0002 seconds for the sampling
  3040. interval between data points of the same channel for the case in which the data
  3041. were sampled at 10000 samples per second.  Although, 0.0001 seconds is the
  3042. sampling interval between adjacent data points in the record, the sampling
  3043. interval for data points of the same channel is a number twice as large.
  3044.  
  3045. 8.2 MAKCOEF routine
  3046.  
  3047.      The primary reason for using unformatted coefficient data files with the
  3048. spectrum routine is to allow the user a means for preparing all of the
  3049. coefficient data for the transformation of voltages into other dimensional
  3050. quantities for several files which will then be processed by SPECTRUM in a
  3051. batch.  The MAKCOEF utility allows the user to prepare this coefficient data in
  3052. an ASCII file; the utility will write the file header and then transfer the
  3053. data to an unformatted coefficient data file which can be read by the spectrum
  3054. routine.
  3055.  
  3056.      Suppose that it was desired to process the data files D061.DAT thru
  3057. D086.DAT in a batch by the spectrum routine.  Each of these data files
  3058. consisted of two channels of 2-byte integers taken from an experiment in fluid
  3059. mechanics, say.  Furthermore, suppose that the quantities sampled were two
  3060. components of a fluid velocity, which were transduced into voltages by some
  3061. means and then sampled by an A/D converter.  The user knows the calibration
  3062. data for the transducer, and the required transformation from voltages back
  3063. into velocities can be accomplished for each velocity component by using a
  3064. polynomial of up to fourth degree in the form:
  3065.  
  3066.  
  3067. [EQUATION "center u sub n #3#3 = #3#3 b sub 0 #3 + #3 b sub 1 v sub n #3 + #3 b
  3068.  
  3069.  
  3070.  
  3071. where  [EQUATION "v sub n", Position:In Text]  is the nth data point expressed
  3072. as a voltage,
  3073. [EQUATION "b sub 0 #1 , #3 b sub 1 #1 , ... , b sub 4", Position:In Text]  are
  3074. the coefficients of the velocity transformation and
  3075. [EQUATION "u sub n", Position:In Text]  is the nth data point which has been
  3076. converted to a velocity.  Now, suppose further that the data in each of the
  3077. files were taken over a period of time in which the calibration coefficients
  3078. changed; thus, a different set of coefficients are required for each of the 26
  3079. files to be processed.  Following the instructions in the section on
  3080. coefficient data files, this scenario would require the creation of two
  3081. unformatted coefficient data files, DCON.DAT and DCON2.DAT, each containing the
  3082. 26 sets of five coefficients
  3083. [EQUATION "b sub 0 #1 , #3 b sub 1 #1 , ... , b sub 4", Position:In Text]  for
  3084. the velocity transformation for channel 1 and channel 2, respectively.
  3085.  
  3086.      The user should create each ASCII data file with a four character name
  3087. followed by the extension [.ASC].  The names should conform to the various
  3088. naming conventions specified earlier.  The ASCII file must contain numbers
  3089. only, although blank lines may be inserted into the file if desired.  The
  3090. numbers will be transferred to 4-byte floating point quantities in the
  3091. unformatted data file thereby limiting the coefficients to single precision (6
  3092. or 7 decimal places).  The coefficients may be stored one per line or many per
  3093. line in the ASCII file.  The first number in the file will be
  3094. [EQUATION "b sub 0", Position:In Text]  for channel 1 of data file D061.DAT;
  3095. the fifth number in the file should be  [EQUATION "b sub 4", Position:In Text]
  3096. for channel 1 of data file D061.DAT; the sixth number in the file will be
  3097. [EQUATION "b sub 0", Position:In Text]  for channel 1 of data file D062.DAT,
  3098. and so on.  The 130th and last number in the file should be
  3099. [EQUATION "b sub 4", Position:In Text]  for channel 1 of data file D086.DAT.
  3100. The user should then create a second ASCII file in a similar manner specifying
  3101. all of the coefficients for channel 2 of the 26 files to be processed.  The
  3102. utility MAKCOEF should then be executed twice, first transferring the contents
  3103. of the first ASCII file (for channel 1) to DCON.DAT and then for the second
  3104. ASCII file (for channel 2) to DCON2.DAT.  A session using MAKCOEF would proceed
  3105. as follows.
  3106.  
  3107.  
  3108. makcoef
  3109.  
  3110. Enter first letter of data file to
  3111. which these coefficients will be associated : d
  3112.  
  3113. Are these coefficients for channel (1 or 2) : 1
  3114.  
  3115. Enter # of sets of coefficients : 26
  3116.  
  3117. Enter starting file number : 61
  3118.  
  3119. Enter ASCII input file name (4 chars) : chn1
  3120.  
  3121.         C O E F F I C I E N T   F I L E   C R E A T I O N   U T I L I T Y
  3122.  
  3123.                        Creating DCON.DAT now.
  3124.  
  3125.                        # sets of coeffs = 26
  3126.                        # coeffs in each set = 5
  3127.                        # of starting file = 61
  3128.  
  3129.                        Program terminated successfully.
  3130.  
  3131.  
  3132. The MAKCOEF routine will read the ASCII file CHN1.ASC and will write the
  3133. following file header to the unformatted file DCON.DAT:
  3134.  
  3135.  
  3136. [EQUATION "center 26 #4#4 61"]
  3137.  
  3138.  
  3139. The coefficients for channel 1 are then transferred to the unformatted file.
  3140. Note that 5 coefficients per set are required; therefore, this number is not
  3141. written to the file header.  If, at a later time, the user wishes to reprocess
  3142. the files D074.DAT through D080.DAT (perhaps specifying different options in
  3143. the spectrum routine), it is not necessary to re-create the two coefficient
  3144. data files; as long as the data files to be reprocessed are chosen from among
  3145. the 26 original members of the set, the spectrum routine will use only the
  3146. coefficients that it needs.  Similarly, if the user wishes to process the data
  3147. files in an arbitrarily numbered order (not consecutively), the coefficient
  3148. data files do not need to be changed as long as the data files come from the 26
  3149. original members of the set.  Thus, D061.DAT, D064.DAT, D069.DAT and D086.DAT
  3150. could be processed by SPECTRUM without changing the coefficient data files.
  3151. The converse is also true, however.  If the user desires at the outset to
  3152. process only the four arbitrarily ordered files above, two coefficient data
  3153. files must be created which contain not 4, but 26 sets of 5 coefficients for
  3154. the data files D061.DAT through D086.DAT.  The spectrum routine requires that
  3155. sets of coefficients in the coefficient data file be listed for consecutively
  3156. numbered files even if not all of the sets of coefficients are used.  With this
  3157. in mind, it is perhaps best to create the coefficient data files for an entire
  3158. set of input data files; then members of the set can be processed by the
  3159. spectrum routine either consecutively or in an arbitrarily numbered order at
  3160. any subsequent time.  Of course, the user could transform the voltages back
  3161. into dimensional quantities using his/her own code and store the resulting
  3162. floating-point numbers into ASCII data files (then use MAKDAT) or directly into
  3163. unformatted data files to be processed by SPECTRUM; then, all of this mess
  3164. concerning coefficient data files could be avoided altogether.
  3165.  
  3166.      Note that the maximum number of points per record is controlled by the
  3167. value of NMAX.  The value of NMAX is currently set to 16384.  The maximum
  3168. number of files that may be processed by SPECTRUM in a batch is controlled by
  3169. the setting of IFMAX; this is currently set to 100.  (If the user should ever
  3170. desire to make a change to the value of NMAX or IFMAX, the change must be made
  3171. both in the MAKCOEF routine and also in the SPECTRUM routine.  NMAX and IFMAX
  3172. must be the same numbers in both routines at all times.)
  3173.  
  3174.                            ^SReferences
  3175.  
  3176. [WHITESPACE 0.1 in, Place All on Next Page]
  3177.  
  3178. Bendat, J.S. and Piersol, A.G. 1986 Random Data, 2nd ed., John Wiley & Sons,
  3179.      Inc., New York.
  3180.  
  3181.  
  3182. Hess, D.E. 1990 An experimental investigation of a compliant surface beneath a
  3183.      turbulent boundary layer. Ph.D. thesis, Johns Hopkins University.
  3184.  
  3185.  
  3186. Microsoft Fortran Optimizing Compiler, Version 5.00, Microsoft Corporation,
  3187.      Redmond, Washington, 1989.
  3188.  
  3189.  
  3190. Press, W.H., Flannery, B.P., Teukolsky, S.A. and Vetterling, W.T. 1986
  3191.      Numerical Recipes, Cambridge University Press, New York.
  3192.  
  3193.  
  3194. Sirivat, A. 1985 Statistical Package for the Analysis of Data (SPAD), private
  3195.      communication.
  3196.  
  3197.  
  3198. Stearns, S.D. 1975 Digital Signal Analysis, Hayden Book Co., Rochelle Park, New
  3199.      Jersey.
  3200.